-->
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: Question about table relations
PostPosted: Sat Feb 12, 2011 3:58 pm 
Newbie

Joined: Sat Feb 12, 2011 3:49 pm
Posts: 13
I have these two entities:

Code:
<hibernate-mapping>
  <class name="com.openkm.dao.bean.Translation" table="OKM_TRANSLATION">
    <property name="module" column="TR_MODULE" length="127" not-null="true"/>
    <property name="key" column="TR_KEY" length="127" not-null="true"/>
    <property name="text" column="TR_TEXT" not-null="true"/>
  </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
  <class name="com.openkm.dao.bean.Language" table="OKM_LANGUAGE">
    <id name="id" column="LG_ID" length="8"><generator class="assigned"/></id>
    <property name="name" column="LG_NAME" length="127" not-null="true"/>
    <property name="imageContent" column="LG_IMAGE_CONTENT" type="text" not-null="true"/>
    <property name="imageMime" column="LG_IMAGE_MIME" length="127" not-null="true"/>
    <set name="translations" table="OKM_TRANSLATION" order-by="TR_KEY asc" cascade="all-delete-orphan" lazy="false">
      <key column="TR_LANGUAGE"/>
      <one-to-many class="com.openkm.dao.bean.Translation"/>
    </set>
  </class>
</hibernate-mapping>


When the table "OKM_TRANSLATION" is created, another column called "TR_LANGUAGE" is created to manage the relation. Well, I need to change the "Translation" mapping to have a composite primary key and following the Hibernate In Action 8.3.1 get this mapping (a little weird for me). The hint is that the "TR_LANGUAGE" field should be included in the primary key:

Code:
<hibernate-mapping>
  <class name="com.openkm.dao.bean.Translation" table="OKM_TRANSLATION">
    <composite-id name="translationId" class="com.openkm.dao.bean.TranslationId">
      <key-property name="module" column="TR_MODULE" length="127"/>
      <key-property name="key" column="TR_KEY" length="127"/>
      <key-property name="languageId" column="TR_LANGUAGE" length="8"/>
    </composite-id>
    <property name="text" column="TR_TEXT" not-null="true"/>
    <many-to-one name="language" class="com.openkm.dao.bean.Language" column="TR_LANGUAGE" insert="false" update="false"/>
  </class>
</hibernate-mapping>


When I try to insert "Translations", Hibernate throws an error because column 'TR_LANGUAGE' cannot be null, but it is not null (at least I put a value on it). I'm lost, any hint?


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.