views:

202

answers:

1

Hi,

I need to update a joined sub-class. Since Hibernate doesn't allow to update joined sub-classes in hql or named-query I want to do it via SQL. I also can't use a sql named-query because updates via named-query are not supported in Hibernate.

So I decided to use a SQLQuery. But Hibernate complaints about not calling addScalar():

org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query.

Are updates returning the number of rows affected and how is named that column?

Are there any other ways to do an update on a joined sub-class in hibernate?

Here is a brief example of what i'm trying to do:

<hibernate-mapping>  
        <class name="example.NiceClass" table="NICE_CLASS">  
  <meta attribute="class-code"></meta>  
  <id name="id" type="java.lang.Long">  
   <column name="NICE_CLASS_ID" precision="8" />  
   <generator class="sequence">  
    <param name="sequence">NICE_CLASS_SEQ</param>  
   </generator>  
  </id>  
    </class>  
</hibernate-mapping>      
<hibernate-mapping package="example">  
    <joined-subclass name="SubJoinedClass" table="SUB_JOINED_CLASS"
     extends="NiceClass">  
        <key column="NICE_CLASS_ID" foreign-key="NICE_JOINED_ID_FK"/>  
  <property name="name" type="string" not-null="false">  
   <column name="NAME" >  
    <comment>name</comment>  
   </column>  
  </property>  
         </joined-subclass>  
</hibernate-mapping>  

Thanks in advance!

so I want to do a:

update SubJoinedClass set name = 'newName'
+1  A: 

How do you execute the update query ? What method do you call to execute it ? Do you call 'ExecuteUpdate' ?

And why do you think that you cannot execute an update query on a subclass using HQL ? AFAIK, it is possible.

Frederik Gheysels
Im using SpringDAOImpl the code:Query namedQuery = session.getNamedQueryAnd I get org.hibernate.QueryException: Update statements against joined or union subclasses not yet supported! Hibernate version 3.0.5Thanks for your quick response!
Udo Fholl
Yes, you're right, but in versions released later that the one we're using (3.0.5).Any of you know how to do that with 3.0.5? thanks
Udo Fholl