-->
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: join table for many to one is not getting created
PostPosted: Wed Jun 04, 2008 9:13 am 
Newbie

Joined: Mon Aug 06, 2007 10:00 am
Posts: 7
Hi All,

I want to make use of join query for many to one relationship.
I have two problem -

1. using hbm2ddl.auto the join table is not getting created. (others are getting created)

Then manually I created the table and started using it. I inserted 1 row in each of joined tables(without any relation b/w them). Later I load both the rows frm tables, put the relation b/w thm and try to update the object.

2. When I set the relation b/w those two, in the join table one entry row should get inserted which will contain IDs from both the table(for joining). But whats happening is instead of insert command, hibernate is running update command -
update midwayhas.APP_BP_DI_MAP set BID=? where DID=?

Can any one tell me why above mentioned 2 issues are there.
Here goes my mapping for two classes -

<class name="com.emc.hpr.databaseapi.threshold.DeviceInstance" table="dwd_instance">
<id name="did" type="integer">
<column name="instancekey" />
<generator class="assigned" />
</id>
<join table="APP_BP_DI_MAP">
<key column="DID" unique="true"/>
<many-to-one name="bPolicy" column="BID" not-null="true" cascade="save-update"/>
</join>
</class>

and

<class name="com.emc.hpr.databaseapi.threshold.BaselinePolicy" table="APP_BASELINE_POLICY">
<id name="bid" type="integer">
<column name="BID" />
<generator class="native" />
</id>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 9:55 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Why do you need a join table for a many to one? Wouldn't it be easier to simply use a foreign key?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 2:25 am 
Newbie

Joined: Mon Aug 06, 2007 10:00 am
Posts: 7
I know that using a foriegn key would have been easier, but my requirement is like that only. Acutally that table is a legacy table and I can not add any extra FK column in to that. Infact I am not going to insert any row also, I will be just creating the relation b/w this table and my new table using this join table.


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.