-->
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.  [ 3 posts ] 
Author Message
 Post subject: one-to-one cascade="all"
PostPosted: Thu Dec 29, 2005 2:45 pm 
Newbie

Joined: Thu Dec 29, 2005 1:35 pm
Posts: 2
Hello,
I have two classes Main and Linked. The relation between them is one-to-one. The ID is generated by Main and referenced by Linked. The classes Main and Linked inherit from BusinessObject which contains an 'ID' property.
If I do
Code:
PersistenceHelper helper = new PersistenceHelper();
Main m = new Main();
helper.Save(m);

(the persistance helper does nothing except a transaction and a standard Save), with the attribute cascade="all" (as it is in the code below), the Main instance is saved but not the Linked instance. If I delete the attribute cascade="all", it works correctly (both instances are stored in the database).
Any idea?
Thanks a lot,
Fred

Mapping documents:
Code:
  <class name="BusinessLayer.Main, BusinessLayer">
    <id name="ID" column="MainID">
      <generator class="hilo"/>
    </id>
    <one-to-one name="Linked" cascade="all"/>
  </class>
 
  <class name="BusinessLayer.Linked, BusinessLayer">
    <id name="ID" column="LinkedID">
      <generator class="foreign">
        <param name="property">Main</param>
      </generator>
    </id>
    <one-to-one name="Main"/>
  </class>


Classes:
Code:
    public class Main : PersistenceFramework.BusinessObject
    {
        public Main() { this._linked = new Linked(this); }
        private Linked _linked;
        public Linked Linked
        {
            get { return this._linked; }
            private set { this._linked = value; }
        }
    }
    public class Linked : PersistenceFramework.BusinessObject
    {
        public Linked(Main main)
        {
            this._main = main;
        }
        private Linked() { }
        private Main _main;
        public Main Main
        {
            get { return this._main; }
            private set { this._main = value; }
        }
    }


Database:
Main(MainID <PK>)
Linked(LinkedID <PK,FK>)
Linked.LinkedID --> Main.MainID[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 12:58 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I think you need to add
Code:
constrained="true|false"
attributes in the <one-to-one> tags, as appropriate (I can't remember offhand which one needs to be true, and which one false -- check the docs)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 3:47 am 
Newbie

Joined: Thu Dec 29, 2005 1:35 pm
Posts: 2
I've already tested with the constrained="true" in Linked, and constrained="false" in Main, like I think it should be done.


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