-->
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.  [ 1 post ] 
Author Message
 Post subject: Saving a object with many-to-one relation
PostPosted: Thu Jan 10, 2008 2:44 pm 
Newbie

Joined: Thu Jan 10, 2008 2:32 pm
Posts: 1
I am having two tables in my database named BlockOrder and Security with many-to-one relation between them, that is many block orders can have same security.

Now, I have to add a new BlockOrder in my database, for an existing security. Security table is read only for me.


[b]blockorder.hbm.xml[/b]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!--dbishn,mjai10,agarg5 -->
<hibernate-mapping default-cascade="none">

<class name="com.sapient.sapetrm.common.domain.BlockOrder" table="TRM_EQUITY_BLOCK_ORDERS" dynamic-insert="false" dynamic-update="false">

<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="EQUITY_BLOCK_ORDERS_ID" />
<generator class="native"/>
</id>

<timestamp name="version" column="TSTAMP"/>

<property name="side" type="java.lang.String">
<column name="SIDE" not-null="true" unique="false" length="5" />
</property>

<property name="status" type="java.lang.String">
<column name="STATUS" not-null="true" unique="false" length="30" />
</property>

<property name="limitPrice" type="java.lang.Double">
<column name="LIMIT_PRICE" not-null="true" unique="false" />
</property>

<property name="stopPrice" type="java.lang.Double">
<column name="STOP_PRICE" not-null="true" unique="false" />
</property>

<property name="totalQuantity" type="java.lang.Double">
<column name="TOTAL_QUANTITY" not-null="true" unique="false" />
</property>

<property name="executedQuantity" type="java.lang.Double">
<column name="EXECUTED_QUANTITY" not-null="true" unique="false" />
</property>

<property name="openQuantity" type="java.lang.Double">
<column name="OPEN_QUANTITY " not-null="true" unique="false" />
</property>

<property name="isMarketPriced" type="java.lang.Character">
<column name="IS_MARKET_PRICED" not-null="true" unique="false" length="1" />
</property>

<many-to-one name="security" class="com.sapient.sapetrm.common.domain.Security" lazy="proxy" fetch="select">
<column name="SECURITIES_ID" not-null="true" unique = "true" />
</many-to-one>

<many-to-one name="trader" class="com.sapient.sapetrm.common.domain.Trader" lazy="proxy" fetch="select">
<column name="TRADERS_ID" not-null="true" />
</many-to-one>

</class>
</hibernate-mapping>



[b]security.hbm.xml[/b]


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- mjai10,agarg5,dbishn -->
<hibernate-mapping default-cascade="none">
<class name="com.sapient.sapetrm.common.domain.Security" table="TRM_SECURITIES" dynamic-insert="false" dynamic-update="false">

<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="SECURITIES_ID" />
<generator class="native"/>
</id>

<timestamp name="version" column="TSTAMP"/>

<property name="type" type="java.lang.String" >
<column name="TYPE" not-null="true" length="30" />
</property>

<property name="symbol" type="java.lang.String">
<column name="SYMBOL" not-null="true" length="30" />
</property>

<property name="name" type="java.lang.String" >
<column name="NAME" not-null="true" length="30" />
</property>

<property name="description" type="java.lang.String">
<column name="DESCRIPTION" not-null="true" length="256" />
</property>

</class>
</hibernate-mapping>


code I am writing is:

public Long addOrUpdateBlockOrder(BlockOrder blockOrder) {
Session session = sessionFactory.openSession();
session.saveOrUpdate(blockOrder);
if(blockOrder.getId()!=null)
return blockOrder.getId();
else{
Query query = session.createQuery("select max(equity_block_orders_id) from trm_equity_block_orders");
List list = query.list();
return (Long)list.get(0);
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.