0

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
  • can youe explain what query you would like to perform on the joined sub-class? Commented Apr 14, 2010 at 12:16

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Im using SpringDAOImpl the code: Query namedQuery = session.getNamedQuery And I get org.hibernate.QueryException: Update statements against joined or union subclasses not yet supported! Hibernate version 3.0.5 Thanks for your quick response!
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.