-->
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: mysql vs. postgresql "group by"
PostPosted: Fri Feb 20, 2004 6:46 am 
Newbie

Joined: Fri Feb 20, 2004 6:26 am
Posts: 12
Hi,

I just ran into an exception while migrating an application from Mysql to Postgresql. It happens in the following query:

final String QUERY =
"select o from " + Order.class.getName() + " as o, " +
PrintJob.class.getName() + " as p" +
" where o.item.info.designID = ?" +
" and p.status != ?" +
" group by o.objId" +
" order by o.orderDate desc";
try {
Session s = session.open();
Object[] args = {label, PrintJob.STATUS_DONE};
Type[] types = {Hibernate.STRING, Hibernate.STRING};
return s.find( QUERY, args, types );
} ...


The code leads to the following exception while using Postgresql, however, it works just fine under Mysql. What am I missing? Any hints appreciated.


-tom

2004-02-20 11:32:16,646 ERROR [http8080-Processor4] (JDBCExceptionReporter.java:46): ERROR: Attribute order0_.deliveryaddress must be GROUPed or used in an aggregate function
2004-02-20 11:32:16,651 ERROR [http8080-Processor4] (JDBCException.java:38): Could not execute query
java.sql.SQLException: ERROR: Attribute order0_.deliveryaddress must be GROUPed or used in an aggregate function
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:153)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1454)
at de.oew.ocp.hibernate.DomainStore.findPendingOrdersForDesign(DomainStore.java:240)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 9:24 am 
Newbie

Joined: Fri Feb 20, 2004 6:26 am
Posts: 12
BTW:

public class Order {
private CalendarModel item;
private int quantity;
private User user;
private Date orderDate;
private Date deliveryDate;
private PaymentInfo paymentInfo;
private Address deliveryAddress;
private Set printJobs = new HashSet();

/**
* @hibernate.set
* lazy="true"
* cascade="all"
* inverse="true"
* @hibernate.collection-key
* column="order_id"
* @hibernate.collection-one-to-many
* column="pjob_id"
* class="de.oew.ocp.print.PrintJob"
*/
public Set getPrintJobs() {
return printJobs;
}

/**
* @hibernate.many-to-one
* cascade="save-update"
*/
public Address getDeliveryAddress() {
return deliveryAddress;
}

/**
* @hibernate.id
* generator-class="native"
* unsaved-value="null"
* column="id"
*/
public Integer getObjId() {
return objId;
}
}

public class PrintJob {
private String status = STATUS_PENDING;
private String barcode;
private int barcodeSuffix;
private Order order;
// yada yada yada
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 10:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/74.html#A12


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 8:23 am 
Newbie

Joined: Fri Feb 20, 2004 6:26 am
Posts: 12
gloeglm wrote:


Thanks, that works.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 3:10 am 
Newbie

Joined: Wed Jan 05, 2005 2:28 pm
Posts: 14
Location: Germany, Munich
michael wrote:


Is that link still valid? I couldn't find any helpful there (and there is no #A12 anchor in that page).


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.