-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL Update doesn't work when updating subclass column
PostPosted: Tue Aug 26, 2008 2:56 am 
Newbie

Joined: Tue Aug 26, 2008 12:30 am
Posts: 1
Hibernate version: 3.2.4sp1

Mapping documents:

Mixing table per class hierarchy with table per subclass

Note: I have changed the class names, table names and column names from the original scenario.

Code:
    <class name="a.b.Class1" table="TABLE1">
         <id column="ID" name="id" type="long" length="10">
           <generator class="native">
                <param name="sequence">SEQ</param>
           </generator>
         </id>
         <discriminator column="TYPE" type="string"/>
         <version column="VERSION" name="version" type="long"/>
         
   <subclass name="a.b.Class2" discriminator-value="TYPE1">
            <join table="TABLE2">
               <key column="ID"/>
               <property name="field1" column="COLUMN1"/>
               <property name="field2" column="COLUMN2"/>
            </join>
   </subclass>
   
   <subclass name="a.b.Class3" discriminator-value="TYPE2">
            <join table="TABLE3">
               <key column="ID"/>
              <property name="field3" column="COLUMN3"/>
            </join>
   </subclass>
    </class>



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

updating a column in subclass table using HQL

Code:
session.createQuery("update Class2 set field2 = :fvalue1 where field1 = :fvalue2")
         .setParameter("fvalue1", "xyz")
         .setParameter("fvalue2", "123")
                   .executeUpdate();



Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


11:49:24,581 DEBUG [SQL]

Quote:

insert
into
HT_TABLE1
select
table0_.ID as ID
from
TABLE1 table0_
inner join
TABLE2 table1_
on table0.ID=table1_.ID
where
TYPE='TYPE1'
and COLUMN1=?
11:49:24,604 TRACE [StringType] binding '123' to parameter: 1
11:49:24,633 DEBUG [SQL]
update
TABLE2
set
COLUMN2=?
where
(
ID
) IN (
select
ID
from
HT_TABLE1
)
11:49:24,657 TRACE [StringType] binding 'xyz' to parameter: 1
11:49:24,837 DEBUG [SQL]
delete
from
HT_TABLE1



I am using Weblogic 9.2 and Spring.

The executeUpdate returns that 1 row has been modified but the changes are not committed to database (it is running in JTA transaction).

When I change it to SQL query it works but not with HQL.

Any explanation?

Thanks


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

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.