java.sql.Timestamp.getTime() not working

#1

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

or

java.lang.ClassCastException

but

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.

#2

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3
Caused by: com.objectdb.o.UserException: Failed to invoke method 'getTime' during query execution
at com.objectdb.o.MSG.d(MSG.java:75)
at com.objectdb.o.MCN.T(MCN.java:273)
at com.objectdb.o.QUN.UC(QUN.java:686)
at com.objectdb.o.PRG.ai(PRG.java:789)
at com.objectdb.o.PRG.ag(PRG.java:713)
at com.objectdb.o.PRG.af(PRG.java:555)
at com.objectdb.o.QRM.U9(QRM.java:286)
at com.objectdb.o.MST.U9(MST.java:988)
at com.objectdb.o.WRA.U9(WRA.java:311)
at com.objectdb.o.WSM.U9(WSM.java:115)
at com.objectdb.o.STC.s(STC.java:464)
at com.objectdb.o.SHN.aj(SHN.java:489)
at com.objectdb.o.SHN.K(SHN.java:155)
at com.objectdb.o.HND.run(HND.java:133)
... 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(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.objectdb.o.MCN.T(MCN.java:267)
... 13 more

for

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

java.lang.ClassCastException in Explorer

#5

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
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login