Hello!
I'm looking for help to build query on calendar class. I need to get objects where Calendar.DAY_OF_WEEK is FRIDAY or any other.
My class:
@Entity public class Cdr { private static final long serialVersionUID = 1L; @Id @GeneratedValue private long serialID; private String A; @Temporal(TemporalType.TIMESTAMP) private Calendar start;
I tested:
Query query=em.createQuery("SELECT c FROM Cdr c where c.start.DAY_OF_WEEK = ?1",Cdr.class); query.setParameter(1,Calendar.FRIDAY);
It throws:
Exception in thread "AWT-EventQueue-0" [ObjectDB 2.5.6_02] javax.persistence.PersistenceException Navigation from 'java.util.Calendar' through 'DAY_OF_WEEK' is invalid (error 763) at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:725) at cdr_analiza.GUI$3.actionPerformed(GUI.java:150) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6505) at javax.swing.JComponent.processMouseEvent(JComponent.java:3320) at java.awt.Component.processEvent(Component.java:6270) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4861) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:708) at java.awt.EventQueue$4.run(EventQueue.java:706) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) Caused by: com.objectdb.o.UserException: Navigation from 'java.util.Calendar' through 'DAY_OF_WEEK' is invalid at com.objectdb.o.MSG.d(MSG.java:61) at com.objectdb.o.QNF.C(QNF.java:925) at com.objectdb.o.QNF.z(QNF.java:789) at com.objectdb.o.QNF.k(QNF.java:258) at com.objectdb.o.QNF.q(QNF.java:518) at com.objectdb.o.QNF.k(QNF.java:189) at com.objectdb.o.QNF.j(QNF.java:135) at com.objectdb.o.QRC.B(QRC.java:340) at com.objectdb.o.QRC.x(QRC.java:231) at com.objectdb.o.QRC.w(QRC.java:185) at com.objectdb.o.QRM.Vb(QRM.java:272) at com.objectdb.o.MST.Vb(MST.java:961) at com.objectdb.o.WRA.Vb(WRA.java:311) at com.objectdb.o.WSM.Vb(WSM.java:115) at com.objectdb.o.QRR.g(QRR.java:247) at com.objectdb.o.QRR.f(QRR.java:153) at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:716)
Could i get some example code of that?
And second part of my question - how to build query on that same class but results should be objects where c.start > {t '23:00:00'}
I tested:
Query query=em.createQuery("SELECT c FROM Cdr c where c.start > {t '23:00:00'}", Cdr.class);
But it throws:
Exception in thread "AWT-EventQueue-0" [ObjectDB 2.5.6_02] SELECT c FROM Cdr c where c.answered ==> > <== {t '23:00:00'} javax.persistence.PersistenceException Operand type mismatch for operator '>' (error 757)
I understand it that Calendar.class could not been compare with {t '23:00:00'}? The only solution is keep time and date i other fields and do that same wiht DAY_OF_WEEK?