-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Max aggregate function not returning same type of argument
PostPosted: Mon May 19, 2008 2:15 pm 
Newbie

Joined: Mon May 19, 2008 1:59 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 2:11 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Related:

http://opensource.atlassian.com/project ... e/HHH-1454

I don't have much to add, except that it seems odd to me as well...

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 2:14 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
And, Max's comment implies that you used the right workaround which is to use Date in your ctor. Timestamp on the db maps to Date in Java, I guess that's what he's saying. So it makes sense, kinda.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 2:44 pm 
Newbie

Joined: Mon May 19, 2008 1:59 pm
Posts: 2
yes seems so...

its quite odd though, and the bug was flagged as rejected/duplicate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 3:10 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
TimestampType does map to Date, though I'm not 100% sure that is what controls this, but I would think it is. You could then create a TimestampTimestampType that maps to java.sql.Timestamp. Though I'm confused b/c the javadoc states that TimestampType maps to either Date or Timestamp...

Code:
public Class getReturnedClass() {
   return java.util.Date.class;
}

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.