-->
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.  [ 6 posts ] 
Author Message
 Post subject: MAX function not working properly with oracle
PostPosted: Mon Apr 18, 2005 6:09 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:02 pm
Posts: 27
Location: New York, NY
I've been attempting to use the MAX aggregate function simply to find the highest current primary key value for a certain object. I've implemented several approaches, the latest of which is shown below and is pretty much straight out of the Hibernate docs.

The problem is the HQL always seems to get translated and the MAX keyword is dropped in the SQL. Please see below how my HQL was converted and the SQL that resulted.

I've looked everywhere but cant find an explanantion. Any help is appreciated.

Thanks





Hibernate version:

HIbernate 2.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():


(this is one of many versions/approaches attempted)


String qryString = "select max(partner.partner_id) from Partner partner";

SessionFactory sf = getHibernateTemplate().getSessionFactory();
Session session = null;
try {
session = sf.openSession();
Iterator result = session.iterate(qryString);
while ( result.hasNext() ) {
Object[] row = (Object[]) result.next();
partnerId = (Long)row[0];

}
} catch (HibernateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}



Name and version of the database you are using:

Oracle 8.1.7

The generated SQL (show_sql=true):

2005-04-18 18:01:02,123 DEBUG [net.sf.hibernate.hql.QueryTranslator] (http-8080-Processor25:) HQL: select max(partner.partner_id) from com.register.rimtools.model.Partner partner
2005-04-18 18:01:02,123 DEBUG [net.sf.hibernate.hql.QueryTranslator] (http-8080-Processor25:) SQL: select partner0_.PARTNER_ID as x0_0_ from PARTNER partner0_

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I got no further than this:

Quote:
Hibernate version:

HIbernate 2.0



Please use a current release.


Top
 Profile  
 
 Post subject: good point
PostPosted: Mon Apr 18, 2005 6:25 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:02 pm
Posts: 27
Location: New York, NY
apologies, we are actually using 2.1.4. I was not specific enough before, but I'll check to see if there is a more recent release available on the 2.1 code base....

thanks


Top
 Profile  
 
 Post subject: sstill no luck...
PostPosted: Mon Apr 18, 2005 7:28 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:02 pm
Posts: 27
Location: New York, NY
ok i tried with the updated 2.1.8 library and still no luck. It looks pretty straight forward, but i must be doing something wrong.

The thing i dont get is it shows the HQL in the log and the SQL its translated to just afterward, and it seems to just completely disregard and drop the "max" directive....

thnx


Top
 Profile  
 
 Post subject: example
PostPosted: Tue Apr 19, 2005 1:26 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:02 pm
Posts: 27
Location: New York, NY
has anyone successfully used the "max" function and can show me a code snippet of their implementation?

thnx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 3:16 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
It work with hibernate 3.0 - I don't know for 2.1

regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.