-->
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: Update HQL for subclass
PostPosted: Tue Apr 24, 2007 12:05 pm 
Newbie

Joined: Thu Mar 10, 2005 9:46 pm
Posts: 2
Location: Baton Rouge, LA
I'm having trouble with executing an update statement against a certain base class. I want the statement to update all members of the base class except those of the subclass. According to the stack trace, it appears that Hibernate is generating the wrong SQL.

Here is my setup and the stacktrace:

Hibernate version:
3.2.1.ga

Mapping documents:
Code:
<?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 package="mypackage.domainobjects" default-lazy="false">

  <class name="BaseClass" table="baseclass" lazy="false">
    <id name="key" column="baseclassid">
      <generator class="assigned"/>
    </id>

    <version column="version" name="version" unsaved-value="null" />   

    <property name="recommended" not-null="true" />

    <joined-subclass name="SubClass" table="subclass" lazy="false">
       <key column="subclassid" />
       <property name="description" not-null="true" />
    </joined-subclass>
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
session.createQuery("update versioned BaseClass bc set bc.recommended = false where bc.class <> SubClass").executeUpdate();

Full stack trace of any exception that occurs:
Code:
org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk update
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:127)
   at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
   at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
   at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
   at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
   at mypackage.domainobjects.IntegrationTest.testQuery(IntegrationTest.java:125)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:164)
   at mypackage.test.HibernateIntegrationTestCase.runBare(HibernateIntegrationTestCase.java:119)
   at junit.framework.TestResult$1.protect(TestResult.java:110)
   at junit.framework.TestResult.runProtected(TestResult.java:128)
   at junit.framework.TestResult.run(TestResult.java:113)
   at junit.framework.TestCase.run(TestCase.java:120)
   at junit.framework.TestSuite.runTest(TestSuite.java:228)
   at junit.framework.TestSuite.run(TestSuite.java:223)
   at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.postgresql.util.PSQLException: ERROR: column "clazz_" does not exist
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:300)
   at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:118)
   ... 24 more

Name and version of the database you are using:
PostgreSQL 8.1.3

The generated SQL (show_sql=true):
Code:
insert into HT_baseclass select baseclass0_.baseclassid as baseclassid  from baseclass baseclass0_ where clazz_<>1



If I use a select statement instead of an update, like this:

Code:
session.createQuery("from BaseClass bc where bc.class <> SubClass").list();

then no error occurs.


Am I doing something wrong?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 9:50 am 
Newbie

Joined: Thu Apr 08, 2004 4:28 am
Posts: 16
I get also this error message.

Used Hibernate version: 3.1.3

Used Database : Oracle 10

Model structure:
Code:
class A {
private int quantity
}

class B extends A {
}

class C extends A {
}


Mapping structure:
Also used "joined-subclass" for the mapping file.

Java Code:
Code:
String sql = "update A set quantity = :newQuanity where oid = :oid";

            Query query = session.createQuery(sql);
            query.setString("oid", a.getOid());
            query.setLong("newQuanity", quanity);
            query.executeUpdate();


SQL output:
Hibernate: insert into HT_A select commercial0_.oid as oid from schema.A commercial0_ where oid=?
Hibernate: delete from HT_A

Error:

Caused by: org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:334)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1126)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at ADAO.updateQuantity(ADAO.java:210)
...
Caused by: java.sql.SQLException: ORA-00942: Tabel of view bestaat niet.

Has someone an idea how we can solve this problem?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 7:05 am 
Newbie

Joined: Thu Apr 08, 2004 4:28 am
Posts: 16
I solved this problem by creating a new table in the database with the 'HT_' prefix.
My table has the name 'HT_A' and it containts only the id field.

But is it not a task for the Hibernate engine to create this temporary table? Or how should we know that Hibernate uses temporary tables?


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.