我正在使用ObjectDB構建Spring MVC應用程序。我的目標是在where子句中使用Java 8 Date and Time作爲查詢參數進行比較。在ObjectDB的查詢中使用LocalDateTime
假設具有測量DateTime對象我有以下實體:
@Entity
public class MyEntity {
@Id @GeneratedValue
private long id;
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTime")
private LocalDateTime dateTime;
//other properties, constructors, getter...
}
與以下庫:
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();
}
現在,如果我在我的庫調用findByTimeSpan
我得到一個空迭代。調用findAll()
而不是給我數據庫中的所有實體(包括它們的正確dateTime)。
我知道這是由於JPA中不存在新的Time API造成的。但是因爲我以前使用HSQLDB和Hibernate作爲持久層(由於性能問題必須切換),我知道即使沒有JPA的支持也是可能的。
是否有解決此問題的任何解決方法?
我的想法,其中:
-write與@Entity
註釋從時間API,包括它們的屬性和委託原來的方法
-persist java.util.Date(或可能java.sql.Timestamp)並使用getter作爲LocalDateTime在代碼中使用
但是我的問題是(除了努力)效率。當軟件投入使用時,數據庫必須存儲超過一百萬個MyEntity類(具有越來越多的數量)的實體,而不是說其他類。
那麼是否有人在ObjectDB中使用LocalDateTime作爲WHERE參數?
預先感謝