I am using Hibernate with the EntityManager and JPA syntax with Annotations.
I have the following named query:
Code:
SELECT NEW mt.com.jbx.EventEntry(p.sender, MAX(p.eventTime)) FROM PendingEvent p WHERE p.recipient.id=? GROUP BY p.sender ORDER BY MAX(p.eventTime) DESC
and the following entity:
Code:
...
import java.sql.Timestamp;
@Entity
@Table(name="pending_events")
public class PendingEvent implements Serializable
{
...
@Column(name="event_time", updatable=false, nullable=false)
private Timestamp eventTime;
...
}
The eventTime is evidently a Timestamp, however when I try to do the max() aggregate function on it, and assign it to the constructor of the EventEntry class (which also takes a Timestamp) it is not accepting it.
Code:
import java.sql.Timestamp;
public class EventEntry
{
private String sender;
private Timestamp lastEventTime;
public EventEntry(String sender, Timestamp lastEventTime)
{
this.sender= sender;
this.lastEventTime = lastEventTime;
}
...
}
The Exception I am getting is:
Code:
java.lang.ExceptionInInitializerError
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: EventsPU] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at mt.com.jbx.EventHandler.<clinit>(EventHandler.java:33)
Caused by: org.hibernate.HibernateException: Errors in named queries: getEventSummary
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:365)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
For some reason, when I changed the lastEventTime to java.util.Date it seems to compile and work fine.
Any ideas why is this? It took me 2hrs to figure out what was happening because the error is so cryptic without any explanation.