-->
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.  [ 7 posts ] 
Author Message
 Post subject: one-to-one mapping
PostPosted: Mon Aug 22, 2005 8:31 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
I'm having a lot of trouble mapping a one-to-one relationship. I tried with a foreign key asscociation and with both table's primary key's matching. Can someone please show me how to do this?
I have 2 tables : QueryGroup and GroupEmailInfo.
I want the QueryGroup class to contain GroupEmailInfo as a member.
When a new queryGroup is saved I want the related GroupEmailInfo to be saved as well with the correct id.

Here are the classes:

Code:
public class Query_Group implements Serializable {


    /** 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;
...

and

public class GroupEmailInfo implements Serializable {

    /** identifier field */
    private Long id;

    /** nullable persistent field */
    private Long group_id; // not necessary - i would only use this for a foreign key asscociation

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

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

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



How would I map this???
Please help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 8:50 am 
Beginner
Beginner

Joined: Tue Jul 05, 2005 4:44 am
Posts: 40
Location: Paris, France
hello tirtzab

for one-to-one relation, my method is to create a many-to-one relation with attribut unique="true" and cascade="all" which is equivalent to the one-to-one relation.

++

_________________
Fred


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 9:01 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
Thanks for your reply.
This is my mapping
Code:
<many-to-one name="groupEmailInfo" class="net.idt.ReportEngine.dao.GroupEmailInfo"       unique="true"  cascade="all"/>


The error I'm getting is

SQLException: ORA-00904: "QUERY_GROU0_"."GROUPEMAILINFO": invalid identifier


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 9:44 am 
Beginner
Beginner

Joined: Tue Jul 05, 2005 4:44 am
Posts: 40
Location: Paris, France
hmmm...

first, I set the attribut column (like GROUP_MAIL_INFO_ID)
second, can you give me the script to create Database

++

_________________
Fred


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 9:44 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
Does the many-to-one have to be inside a parent element?
Here is my mapping
Code:
      <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"/>
                      <many-to-one name="groupEmailInfo" class="net.idt.ReportEngine.dao.GroupEmailInfo"
                      unique="true"  cascade="all" property-ref="group_id" />
                           
        </class>

        <class name="net.idt.ReportEngine.dao.GroupEmailInfo" table="tre.Group_Email_Info">
               <id name="id" column="Group_Email_Info_Id" >
                          <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>



I am getting this error:
SQLException: ORA-00904: "QUERY_GROU0_"."GROUPEMAILINFO": invalid identifier


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 9:58 am 
Newbie

Joined: Wed Aug 10, 2005 6:49 am
Posts: 10
Am I doing the many-to-one on the wrong side? Should it be defined in the GroupEmailInfo?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 3:10 am 
Beginner
Beginner

Joined: Tue Jul 05, 2005 4:44 am
Posts: 40
Location: Paris, France
I think your error is to set property-ref="group_id".
property-ref is used to have a bi-directionel relation like Query_Group <-> GroupEmailInfo.
You can try this :
Code:
                       <many-to-one name="groupEmailInfo" class="net.idt.ReportEngine.dao.GroupEmailInfo"
                      unique="true"  cascade="all" column="GROUP_ID" />


++

_________________
Fred


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