3

I am building a Spring MVC application using ObjectDB. My aim is to use the Java 8 Date and Time as a query parameter for comparison in the where clause.

Let's assume I've got following entity having a measurement datetime object:

@Entity
public class MyEntity {
    @Id @GeneratedValue
    private long id;

    @Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTime")
    private LocalDateTime dateTime;

    //other properties, constructors, getter...
}

And following repository:

public interface EntityRepository extends CrudRepository<MyEntity, Long> {
    @Query("SELECT e FROM MyEntity e WHERE e.dateTime BETWEEN ?1 AND ?2")
    Iterable<MyEntity> findByTimeSpan(LocalDateTime start, LocalDateTime end);

    Iterable<MyEntity> findAll();
}

Now, if I invoke findByTimeSpan on my repository I am getting an empty iterable. Calling findAll() instead gives me all entities in the database (including their correct dateTime).

I know that this is caused by the non existence of the new Time API in JPA. But since I previously used HSQLDB with Hibernate as persistence layer (had to switch due to perfomance issues), I know that it is possible even without support by JPA.

Is there any workaround known for this issue?

My ideas where:

-write a wrapper annotated with @Entity for each used class from the Time API including their properties and delegating to the original methods

-persist java.util.Date (or maybe java.sql.Timestamp) and use a getter for usage as LocalDateTime in Code

But my problem is (additionally to the effort) the efficiency. When the software goes into productive use, the database has to store more than a million entities of class MyEntity (with growing number), not to speak of other classes.

So is anyone having a solution for using LocalDateTime as WHERE parameter in ObjectDB?

Thanks in advance

Stephan
  • 281
  • 1
  • 7

1 Answers1

0

LocalDateTime is currently not supported by ObjectDB (and JPA) as a date / time type. It may still be supported as any other Serializable type for storage but not for querying.

Accordingly you will have to use a standard JPA date / time type, and possibly provide wrapper methods for converting values to and from LocalDateTime.

ObjectDB
  • 1,294
  • 7
  • 8