java.sql.Timestamp.getTime() not working


Hi, I need to work with Timestamp diff in two entity fields, but this queries

SELECT count(p) FROM Player p WHERE p.loginAt.getTime()-p.registeredAt.getTime()>:value
SELECT p.loginAt.getTime() FROM Player p

fails with

object is not an instance of declaring class




SELECT p.loginAt.getYear() FROM Player p

works. How that possible?


@Entity public class Player {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) public int id;
@Temporal(TemporalType.TIMESTAMP) public Timestamp loginAt;
@Temporal(TemporalType.TIMESTAMP) public Timestamp registeredAt = AppCore.getTime();



Is there some other way to compare two Timestamps within ObjectDB not to transfering them to Java? Because there about 10^6 records.


Please post full stack traces and report which query produces which error exactly.

ObjectDB Support
Caused by: com.objectdb.o.UserException: Failed to invoke method 'getTime' during query execution
at com.objectdb.o.MSG.d(
at com.objectdb.o.MCN.T(
at com.objectdb.o.QUN.UC(
at com.objectdb.o.QRM.U9(
at com.objectdb.o.MST.U9(
at com.objectdb.o.WRA.U9(
at com.objectdb.o.WSM.U9(
at com.objectdb.o.STC.s(
at com.objectdb.o.SHN.aj(
at com.objectdb.o.SHN.K(
... 1 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.objectdb.o.MCN.T(
... 13 more


SELECT p.registeredAt.getTime() FROM Player p WHERE p.registeredAt!=null

java.lang.ClassCastException in Explorer


Due to limitation of ObjectDB methods from java.sql types, including Time, Date and Timestamp are not supported directly.

The workaround is to use casting:

SELECT ((java.sql.Timestamp)p.loginAt).getTime() FROM Player p

or to use java.util.Date instead of Timestamp if applicable.

ObjectDB Support