[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3320?page=c...
]
josef updated HHH-3320:
-----------------------
Attachment: HibernateUnitTest.zip
Unit test and respective classes attached.
Under /test: hibernateunittest.timestampfault.HibernateTimestampTest
(creates some rows in the database during test setup and then executes the test.)
Under /src/META-INF: persistence.xml (modify according to your environment)
Under /dist/lib: all the libraries you should need.
Under /src: actual entity classes
hibernateunittest.timestampfault.Sender (the parent of the OneToMany relationship, also
defines the namedQuery that uses MAX() aggregate on timestamp)
hibernateunittest.timestampfault.PendingEvent (the child of the OneToMany, defines the
Timestamp member eventTime)
hibernateunittest.timestampfault.LastSenderEventTime (the aggregation class, intending to
represent a Sender and the last time he had an event)
If the eventTime is changed from Timestamp to Date everything works fine. If it is left to
javax.sql.Timestamp the following exception is occurring:
Stderr:
SEVERE: Unable to locate appropriate constructor on class
[hibernateunittest.timestampfault.LastSenderEventTime]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class:
hibernateunittest.timestampfault.LastSenderEventTime]
18-Jun-2008 12:47:32 org.hibernate.impl.SessionFactoryImpl <init>
SEVERE: Error in named query: getLatestEventTimes
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on
class [hibernateunittest.timestampfault.LastSenderEventTime] [SELECT NEW
hibernateunittest.timestampfault.LastSenderEventTime(p.sender.id, MAX(p.eventTime)) FROM
hibernateunittest.timestampfault.PendingEvent p GROUP BY p.sender.id ]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:402)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:352)
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)
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
hibernateunittest.timestampfault.HibernateTimestampTest.<clinit>(HibernateTimestampTest.java:23)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:336)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:912)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:766)
Stdout:
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: HibernateUnitTestPU]
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
hibernateunittest.timestampfault.HibernateTimestampTest.<clinit>(HibernateTimestampTest.java:23)
Caused by: org.hibernate.HibernateException: Errors in named queries: getLatestEventTimes
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)
JPA Max/Min aggregate functions do not return same state-field type
when argument is a java.sql.Timestamp
---------------------------------------------------------------------------------------------------------
Key: HHH-3320
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3320
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.3.0.CR1
Environment: JDK 1.6, Postgres 8.2, JDBC 4
Reporter: josef
Attachments: HibernateUnitTest.zip
According the JPQL specification, MAX and MIN aggregate functions should return the type
of the state-field to which they are applied. However, if one tries to query MAX or MIN on
a java.sql.Timestamp entity field and tries to populate a class which expects a
java.sql.Timestamp in the constructor with the result of MAX or MIN, Hibernate fails with
javax.persistence.PersistenceException. The result of MAX or MIN in this case are being
java.util.Date instead.
The error result in type mismatch should ideally also be more helpful, because it is very
difficult to understand what and where the problem is, unless you know about it
beforehand.
Here is an example Entity, with the aggregate class and query, together with the
exception that occurs:
...
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;
...
}
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;
}
...
}
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
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)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira