-->
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: Cascading for static values
PostPosted: Thu Mar 16, 2006 8:08 pm 
Newbie

Joined: Tue Mar 14, 2006 3:58 pm
Posts: 3
I'm fairly new to Hibernate (using Hibernate 3) so for the past couple of days I've been struggling with the following:

I have a Campaign object which has a reference to a GeoTarget object that can be reused accross multiple campaigns. In a turn, GeoTarget consists of two lists one for the countries and another one for the regions. Each individual country or region is represented by Constant object that provides string value (e.g. USA) and description. Once country or region value is defined, I want to reuse it in the future mappings so the constant is mapped as many-to-many. The problem is that when I try to cascade on new or existing campaign object Hibernate will attempt to insert new constant value regardless if it's already exists in the table.

So, the question is - can cascading be done at all or should I remove cascade and do SELECT on each Constant object everytime I need to add another campaign?

The following are HBM snippets:

Campaign.hbm
Code:
   <class name="CampaignBean" table="CAMPAIGNS">
      ... id + props
      <many-to-one name="geoTargeting" column="GEO_TARGET_ID" class="GeoTargetBean"
            lazy="proxy" cascade="merge"/>
   </class>


GeoTarget.hbm
Code:
   <class name="GeoTargetBean" table="GEO_TARGETS">
      ... id + props
      <list name="countries" table="GEO_COUNTRIES" lazy="true" cascade="merge">
         <key column="PARENT_ID"/>
         <list-index column="ID"/>
         <many-to-many column="CONSTANT_ID" class="Constant"/>
      </list>
      <list name="regions" table="GEO_REGIONS" lazy="true" cascade="merge">
         <key column="PARENT_ID"/>
         <list-index column="ID"/>
         <many-to-many column="CONSTANT_ID" class="GoogleConstant"/>
      </list>
   </class>


Constant.hbm
Code:
   <class name="Constant" table="CONSTANTS" select-before-update="true">
      <id name="id" column="ID" type="long">
         <generator class="native">
            <param name="sequence">seq_google_const</param>
         </generator>
      </id>
<!-- When I set unique="false" everything works but I get bunch of duplicates in CONSTANTS table -->
      <property name="value" type="string" not-null="true" column="VALUE" unique="true"/>
      <property name="description" type="string" column="DESCRIPTION"/>
   </class>



P.S. I tried all flavors of cascade including "all" and combinations such as "merge, save-update"


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.