-->
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: Foreign key not saved in one-to-one relation
PostPosted: Mon May 26, 2008 2:53 am 
Newbie

Joined: Sat May 24, 2008 6:20 am
Posts: 6
I have two tables: option_position and stock_trading. The relation is one option_position contains one stock_trading. Here is the def:

Table option_position:
id -- primary key, auto increment

Table stock_trading:
id -- primary key, auto increment
option_position_id -- foreign key to option_position table

Here is the OptionPosition.hbm.xml:

<hibernate-mapping default-lazy="false">

<class name="com.ameraust.investor.option.strategy.OptionPosition" table="option_position">
<id name="id" type="int" column="id">
<generator class="increment"/>
</id>

<one-to-one name="initialStockTrading" class="com.ameraust.investor.object.StockTrading" property-ref="optionPosition" constrained="true" cascade="all" />
....

Here is the StockTrading.bhm.xml:

<hibernate-mapping default-lazy="false">

<class name="com.ameraust.investor.object.StockTrading" table="stock_trading">

<id name="id" type="int" column="id">
<generator class="increment"/>
</id>

<many-to-one name="optionPosition" class="com.ameraust.investor.option.strategy.OptionPosition" column="option_position_id" unique="true"/>
...


When calling session.save(optionPosition), one row created in each table. But option_position_id = null in stock_trading table.

What's wrong here?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 4:20 pm 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
Quote:
When calling session.save(optionPosition), one row created in each table. But option_position_id = null in stock_trading table.

Could you clarify a bit more what is going on? Some program code?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 26, 2008 11:42 pm 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
The optionposition call should explicitly set its value in stock_trading. You could look at Item, Bid example in Java Persistance with hibernate example or

https://glassfish.dev.java.net/javaee5/ ... ample.html

Regards,
Nagendra

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


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.