-->
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.  [ 8 posts ] 
Author Message
 Post subject: one-to-one foreign key assosciation
PostPosted: Wed Aug 10, 2005 7:01 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
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).


Top
 Profile  
 
 Post subject: Re: one-to-one foreign key assosciation
PostPosted: Wed Aug 10, 2005 9:08 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
tirtzab wrote:
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).


<one-to-one>'s need to be defined on both sides.

Look at the example on page 61 of the 3.0.5 docs - section 6.1.11.

_________________
Preston

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 10:25 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
When I put the many-to one in the GroupEmailInfo I get the following error
HibernateSystemException: exception setting property value with CGLIB
setter of net.idt.ReportEngine.dao.GroupEmailInfo.setGroup_id; 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"
/>


</class>


Top
 Profile  
 
 Post subject: property
PostPosted: Wed Aug 10, 2005 11:04 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
make sure that property groiup_id of GroupEmailInfo class has type net.idt.ReportEngine.dao.Query_Group and probably ( I suggest renaming it to group, since it holds class, not just id )


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 2:31 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
GroupEmailInfo does not contain Query_Group. It contains the id to Query_Group called group_id. group_id is a long. The QueryGroup class contains GroupEmailInfo as a member called groupEmailInfo.


public class Query_Group implements Serializable {

Logger logger = Logger.getLogger(Query_Group.class.getName());

/** identifier field */
private Long id;

/** nullable persistent field */
private String interval;

/** nullable persistent field */
private Timestamp last_run_dte;

/** nullable persistent field */
private String group_name;

/** nullable persistent field */
private String group_status_cde;

/** nullable persistent field */
private net.idt.ReportEngine.dao.GroupEmailInfo groupEmailInfo;
...

public class GroupEmailInfo implements Serializable {

/** identifier field */
private Long id;

/** nullable persistent field */
private Long group_id;

/** nullable persistent field */
private String subject;

/** nullable persistent field */
private String body;

/** nullable persistent field */
private String from_address;
...




Top
 Profile  
 
 Post subject: Check if this helps
PostPosted: Tue Aug 16, 2005 4:29 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Hi Friend,
Im newbie in Hibernate. I too have had some torrid time with this irritating issue.

But I somehow managed to get through by saving Parent First and then Child next.

For ex, session.save(parent);
session.save(child);
This will issue two queries and you no need to worry about how child takes parent's ID. Hibernate would do it for you. Let me know if this helps you.

Thanks and Regards,
Aru K


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 3:04 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
Thanks but i would like to actually solve the issue not try to get around it. I know there must be a way to do this.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 10:47 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
do i need to define one-to-one on both sides? I do not want my GroupEmailInfo to contain Query_group as a member. I want Query_group to contain Group_Email_Info as a member.

Please help!! thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.