-->
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.  [ 3 posts ] 
Author Message
 Post subject: createQuery including a scalar on mapping w/composite id
PostPosted: Mon Oct 24, 2005 3:32 pm 
Beginner
Beginner

Joined: Mon Sep 05, 2005 4:48 pm
Posts: 31
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.KeyControlDTO"
table="billing_data_mart_db.KeyControl" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<composite-id name="id" class="ami.server.dto.datamart.billing.KeyControlId">
<key-property name="dimensionName" type="string" column="dimension_name"/>
<key-property name="oltpKey" type="long" column="oltp_key"/>
</composite-id>
<property name="olapKey" type="long" column="olap_key"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Query bdmDelete = session.createQuery("delete " + persistenceObj);
bdmDelete.executeUpdate();
bdmRows = (Integer)session.createQuery("select count(pObj) from " + persistenceObj +
" pObj").uniqueResult();


Full stack trace of any exception that occurs:
15:07:06,244 WARN [JDBCExceptionReporter] SQL Error: 1241, SQLState: 21000
15:07:06,245 ERROR [JDBCExceptionReporter] null, message from server: "Operand should contain 1 column(s)"
15:07:06,245 ERROR [UtilBmBean] org.hibernate.exception.GenericJDBCException: could not execute query


Name and version of the database you are using:MySQL 4.1.14

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

When attempting to delete and then subsequently check for the success of the delete, I receive an expection that looks like it has something to do w/a sub-query in MySQL. I assume this is because the mapping for the object deleted contains a composite key. That is the only thing that appears to be the likely culprit at this point. I have many other objects I pass to this method(contained as the value of 'persistenceObj') and the error does not appear for any of them. All of these other objects contain a simple id, not a composite.

How do you use a scalar on an object containing a composite key using the Query interface?

Mark


Top
 Profile  
 
 Post subject: Re: createQuery including a scalar on mapping w/composite id
PostPosted: Tue Nov 08, 2005 6:26 pm 
Newbie

Joined: Tue Nov 08, 2005 6:10 pm
Posts: 1
Hi "mark_in_gr",

Do you still have this problem or could you found a solution?
I have a similar or same problem since I swirched from hibernate2 to Hibernate version: 3.0.5 .

Could you please provide the generated SQL Statement!? In my case I found that the generated query is wrong. I dont understand why and how to fix this.


In my case the generated query is:

Code:
select count(*) as col_0_0_ from WebLogEntry weblogentr0_ where webLogID='8a80b8cf069ee33901069ee365bb0006' order by (weblogentr0_.position, weblogentr0_.webLogID)


My SourceCode and query is:

Code:
SELECT COUNT(*) FROM WebLogEntry WHERE  webLogID = '8a80b8cf069ee33901069ee365bb0006' ORDER BY position

Query q = session.createQuery(countQuery);
Integer count = (Integer)q.uniqueResult();




I found that problem are the brackets in the order by section. If I remove them it is no problem to execute the query.

Greetings,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 10:43 pm 
Beginner
Beginner

Joined: Mon Sep 05, 2005 4:48 pm
Posts: 31
Hi Criss:

Sorry for the late reply. I have not looked into this and have since re-written the query to work another way. I will take a look at the original and see if I can get more information for you,

Regards,

Mark


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