177 words

java.sql.Timestamp.getTime() not working

#1
2016-11-27 19:51

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.

mastervoland
mastervoland's picture
Joined on 2014-01-25
User Post #19
#2
2016-11-28 10:13

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,665
#3
2016-11-28 11:36
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
mastervoland
mastervoland's picture
Joined on 2014-01-25
User Post #20
#4
2016-11-28 14:48

java.lang.ClassCastException in Explorer

mastervoland
mastervoland's picture
Joined on 2014-01-25
User Post #21
#5
2016-11-29 00:27

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)
support
support's picture
Joined on 2010-05-03
User Post #2,666

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel