-->
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.  [ 2 posts ] 
Author Message
 Post subject: mapping to same class several times using the same key
PostPosted: Wed Jan 12, 2011 3:08 am 
Newbie

Joined: Wed Jan 12, 2011 2:42 am
Posts: 4
Hi,

I wasnt able to find a solution to my problem (maybe i was looking wrong places or searching wrong things dont know).

I have 2 tables = newsletter_templates and newsletter_template_settings. i am trying to map template settings several times to be able to use them by names i define.

I can actually just take all of settings using 1 list then separate them in JAVA but i'm trying to retrieve the data separately and be able to insert/update the settings table directly. when i try the mapping below i get an exception:

......
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.overteam.framework.persistent.NewsletterTemplateSettingsData column: template_id (should be mapped with insert="false" update="false")
......

i already mapped template_id column as it says but still get the exception. so i cant even try if i am able to do this. any help would be great.

Thanks..

my xmls are as follows:

-newsletterTemplateSettings
Code:

<class name="com.overteam.framework.persistent.NewsletterTemplateSettingsData" table="newsletter_template_settings">
   <id name="id" column="id" type="long" >
      <generator class="sequence" >
         <param name="sequence">newsletter_template_settings_id_sequence</param>
      </generator>
   </id>
 
   <property name="created" column="created" type="timestamp" not-null="true"/>
   <property name="modified" column="modified" type="timestamp" not-null="true"/>
   <property name="creatorId" column="creator_id" type="long" not-null="true"/>
   <property name="modifierId" column="modifier_id" type="long" not-null="true"/>
   <property name="status" column="status" type="string" length="1"/>
   
   <property name="templateId" column="template_id" type="long" not-null="true" insert="false" update="false"/>
   
   <property name="type" column="typ" type="int" not-null="true"/>
   <property name="objectId" column="object_id" type="long" not-null="false"/>      
        <property name="body"   column="body" type="string" length="65535"/>
      
   <property name="active" column="active" type="boolean" not-null="true"/>
</class>


-newsletterTemplate
Code:

<class name="com.overteam.framework.persistent.NewsletterTemplateData" table="newsletter_templates">
   <id name="id" column="id" type="long" >
      <generator class="sequence" >
         <param name="sequence">newsletter_templates_id_sequence</param>
      </generator>
   </id>
 
   <property name="created" column="created" type="timestamp" not-null="true"/>
   <property name="modified" column="modified" type="timestamp" not-null="true"/>
   <property name="creatorId" column="creator_id" type="long" not-null="true"/>
   <property name="modifierId" column="modifier_id" type="long" not-null="true"/>
   <property name="status" column="status" type="string" length="1"/>
      
   <property name="type" column="typ" type="int" not-null="true"/>
   <property name="title" column="title" type="string" not-null="true" length="511" />
   <property name="headerArticle" column="header_article" type="long" not-null="true"/>
   <property name="headerImage" column="header_image" type="string"/>
   <property name="sent" column="sent" type="boolean" not-null="true" />
   <property name="toWho" column="to_who" type="int" not-null="true"/>
      
      
   <bag name="siteRestrictions" cascade="all" lazy="false" where="typ = 1" order-by="id">
      <key column="template_id" not-null="true"/>
      <one-to-many  class="com.overteam.framework.persistent.NewsletterTemplateSettingsData"  not-found="ignore"/>
   </bag>
      
   <bag name="displayHeader" cascade="all" lazy="false" where="typ = 2 and object_id = 1">
      <key column="template_id" not-null="true" />
      <one-to-many class="com.overteam.framework.persistent.NewsletterTemplateSettingsData"  not-found="ignore" />
   </bag>
      
   <bag name="displayHeaderCustomize" cascade="all" lazy="false" where="typ = 2 and object_id = 2">
      <key column="template_id" not-null="true" />
      <one-to-many class="com.overteam.framework.persistent.NewsletterTemplateSettingsData"  not-found="ignore" />
   </bag>
         ........................... and keeps going for other settings
</class>


Top
 Profile  
 
 Post subject: Re: mapping to same class several times using the same key
PostPosted: Wed Jan 12, 2011 4:56 am 
Newbie

Joined: Wed Jan 12, 2011 2:42 am
Posts: 4
ok found it, just adding inverse="true" to bags fixes it.

but i now have a bigger problem. i need to get a single data and not a collection from some of these bags.

my getters and setters give error as they cant convert collection to my actual class, i worked a way around and changed getters and setters to work with lists but is there a normal way to do it?


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