-->
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: Persist one-to-one field object
PostPosted: Sat Dec 31, 2005 4:06 pm 
Newbie

Joined: Sat Dec 31, 2005 3:51 pm
Posts: 2
Hello,

I'm new to Hibernate and have what I am sure is a simple problem.

I have two classes like this:

Code:
class Order {
 
   Lond id;
   Date ts;
   double amount;
   State state;
   
   // getters and setters...
  }

class State {
   Long id;
   String desc;
   int qty;
   ...
}


The mapping for Order is summarised:

Code:
   <class name="Order" table="ORDER">
      <id name="id" column="ORDER_ID">
         <generator class="native"/>
      </id>
      <property name="ts" type="timestamp" column="TS"/>
      <property name="amount"/>
      <one-to-one name="state" cascade='all'/>
   </class>


and for State:

Code:
   <class name="State" table="STATE">
      <id name="id" column="STATE_ID">
         <generator class="native"/>
      </id>
      <property name="desc"/>
      <property name="qty"/>
   </class>


the problem: I can save order objects ok, but the state field never gets persisted - its always null.

I'm sure its solvable but I can't see it - any tips appreciated :)

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 31, 2005 5:23 pm 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Shouldn't there be something like

<one-to-one name="state" class="State" cascade='all'/>

???

Otherwise I use a very similar mapping that works.

I also use

Code:
        <id name="id" column="USER_ID">
            <generator class="foreign">
                <param name="property">user</param>
            </generator>
        </id>


in the referenced class to join the key generation with base object (this is I believe somewhere in the docs).

All the best,

René


Top
 Profile  
 
 Post subject: Got there, more or less
PostPosted: Tue Jan 03, 2006 1:35 pm 
Newbie

Joined: Sat Dec 31, 2005 3:51 pm
Posts: 2
Thanks for your help René.

So far the solution I'm using was to use many-to-one and just live with it not being too intuitive (to me that is):

Code:
  <many-to-one name="state" fetch="join" cascade='all' column='STATE' />


I would have liked to use a foreign key or a composite key because the state property doesn't really need its own Long key.

But for simplicity, I've given it a plain old Long key. It works, so I'm not going to fight it ;)


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.