Use LocalDateTime in Request in ObjectDB

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

Suppose I have the following entity that has a dimension 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 the 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 call findByTimeSpan

in my repository I get an empty iterable. The call findAll()

instead gives me all the entities in the database (including their correct DateTime).

I know this is caused by the lack of a new time API in JPA. But since I previously used HSQLDB with Hibernate as persistence layer (had to switch due to performance issues), I know this is possible even without JPA support.

Is there any workaround known for this issue?

My ideas where:

-write wrapper annotated @Entity

for every used class from the Time API, including their properties and delegation to the original methods

-perist java.util.Date (or maybe java.sql.Timestamp) and use getter to use as LocalDateTime in code

But my problem (in addition to the effort) is efficiency. When software goes into production use, the database needs to store over a million objects of the MyEntity class (with a growing number) and not talk about other classes.

Anyone have a solution for using LocalDateTime as WHERE parameter in ObjectDB?

Thank you in advance

+3


source to share


1 answer


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



Accordingly you will have to use the standard JPA date / time type and possibly provide wrapper methods to convert values ​​to and from LocalDateTime.

0


source







All Articles