Announcement Announcement Module
Collapse
No announcement yet.
one-to-one foreign key assosciation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • one-to-one foreign key assosciation

    I have a one-to-one mapping based on a foreign key association. It is able to pull the related data.
    The problem is: when saving it does not put in an id into the foreign key of the related data .

    <class name="net.idt.ReportEngine.dao.Query_Group" table="tre.Query_Group">
    <id name="id" column="query_group_id" type="long">
    <generator class="sequence">
    <param name="sequence">tre.QUERY_GROUP_SEQ</param>
    </generator>
    </id>
    <property name="interval" type="string"/>
    <property name="last_run_dte" type="timestamp"/>
    <property name="group_name" type="string"/>
    <property name="group_status_cde" type="string"/>

    <one-to-one name="groupEmailInfo" class="net.idt.ReportEngine.dao.GroupEmailInfo"
    property-ref="group_id" cascade="all" constrained ="true"/>

    </class>

    <class name="net.idt.ReportEngine.dao.GroupEmailInfo" table="tre.Group_Email_Info">
    <id name="id" column="Group_Email_Info_Id" type="long" unsaved-value="0">
    <generator class="increment"/>
    </id>
    <property name="group_id" type="long"/>
    <property name="subject" type="string"/>
    <property name="body" type="string"/>
    <property name="from_address" type="string"/>
    </class>


    To clarify: My Query_Group class contains GroupEmailInfo as a member.
    A select on a specific Query_Group includes the correct GroupEmailInfo.
    However when saving a new Query_Group (with a GroupEmailInfo ) then
    the GroupEmailInfo that is inserted into the db has a null value in group_id(the foregn key).

    So I thought I had to put a many-to-one in GroupEmailInfo.
    When I do that I get
    HibernateSystemException: exception setting property value with CGLIB
    setter of net.idt.ReportEngine.dao.GroupEmailInfo.setGroup_i d; nested exception is net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB


    <class name="net.idt.ReportEngine.dao.GroupEmailInfo" table="tre.Group_Email_Info">
    <id name="id" column="Group_Email_Info_Id" type="long" unsaved-value="0">
    <generator class="increment"/>
    </id>

    <property name="subject" type="string"/>
    <property name="body" type="string"/>
    <property name="from_address" type="string"/>

    <many-to-one name="group_id" class="net.idt.ReportEngine.dao.Query_Group" column="group_id"
    />
Working...
X