-->
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.  [ 6 posts ] 
Author Message
 Post subject: Inheritance mapping - parent and children unsynchronized
PostPosted: Mon Oct 17, 2005 8:24 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
Hi, I have a following problems
I have a entity Service which is a parent to UserService. When I try to save UserService which violates unique constraint on userServiceName child object is not being saved while the parent is and exception is thrown
Am i missing something in the mapping?
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>
   <!--
      Auto-generated mapping file from
      the hibernate.org cfg2hbm engine
   -->
   <class name="model.Service" table="Service">
      <id name="serviceId" type="long">
         <column name="serviceid" precision="22" scale="0" />
         <generator class="sequence">
            <param name="sequence">ServiceID_sq</param>
         </generator>
      </id>

      <discriminator column="serviceTypeId"/>

      <version name="beanVersion"
         column="version_"
         type="long" />
      
      <property name="name" type="string">
         <column name="name" length="80" not-null="true" />
      </property>
      <property name="description" type="string">
         <column name="description" length="4000" />
      </property>

      <property name="serviceTypeId" type="long" insert="false" update="false">
         <column name="serviceTypeId" precision="22" scale="0" />
      </property>
      
      <subclass name="model.UserService" discriminator-value="1">
         <join table="UserService" >
            <key column="UserServiceId" />
            <property name="userServiceName" column="userServiceName" not-null="true" unique="true" />
         </join>
         
      </subclass>

      

   </class>
</hibernate-mapping>



_________________
www.globalresearch.ca


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:43 am 
Newbie

Joined: Mon Jan 17, 2005 1:09 pm
Posts: 19
check te reference manual page 100:
"There is one big limitation of this subclasses,such as CCTYPE, may not have NOT NULL constraints."


Code:
      <subclass name="model.UserService" discriminator-value="1">
         <join table="UserService" >
            <key column="UserServiceId" />
            <property name="userServiceName" column="userServiceName" not-null="false" unique="true" />
         </join>
         
      </subclass>


set the not-null contraint from true to false


ps)don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:56 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
I dont have problem with not null constraint but with unique constraint and i'm using table per subclass strategy with discriminator

_________________
www.globalresearch.ca


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 9:17 am 
Newbie

Joined: Mon Jan 17, 2005 1:09 pm
Posts: 19
Sorry, I was a little bit to fast in replying.

Maybe the following thing is the problem:

you have a discrimator and a property both named: serviceTypeId. That seems rather odd to me.



Code:
     <discriminator column="serviceTypeId"/>

      <version name="beanVersion"
         column="version_"
         type="long" />
       
      <property name="name" type="string">
         <column name="name" length="80" not-null="true" />
      </property>
      <property name="description" type="string">
         <column name="description" length="4000" />
      </property>

      <property name="serviceTypeId" type="long" insert="false" update="false">
         <column name="serviceTypeId" precision="22" scale="0" />
      </property>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 9:59 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Are you using Transactions ? If not, my assumption would be that the parent insert is being performed prior to the ConstraintViolation which is causing the second insert to fail.

If you are using Txns, can you provide your log and stacktrace ?

(BTW: There's nothing wrong with having the same column as a descriminator and a property but it's unnecessary. You could just supply the name="" attribute on the <descriminator> tag and it would handle both situations.)

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 11:18 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
Im not using Hibernate API directly. Im using spring on top of hibernate but you were rigth. It seems that transactions were not activated

_________________
www.globalresearch.ca


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