-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to create Many to One assocation where no foreign key
PostPosted: Tue Mar 09, 2010 6:26 am 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
Auditlog
long auditlog_id PK
string businessname
long businessid
...

Cancellation
long cancellation_id PK
...

I have above two Tables
Auditlog and Cancellation

When Auditlog's businessname is "Cancellation", then Auditlogçš„ businessid is Cancellation's cancellation_id

If I could use HQL to describe the relation between Cancellation and Auditlog , it looks like below

select cancel from Cancellation cancel, Auditlog audit where audit.businessname="CANCELLATION" and
audit.businessid=cancel.cancellation_id ;

Then my question is how do I write many-to-one relation in Auditlog.hbm.xml ?

Thanks and Rgds


Top
 Profile  
 
 Post subject: Re: How to create Many to One assocation where no foreign key
PostPosted: Tue Mar 09, 2010 6:56 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Check the <any> example here: http://docs.jboss.org/hibernate/stable/ ... anymapping


Top
 Profile  
 
 Post subject: Re: How to create Many to One assocation where no foreign key
PostPosted: Wed Mar 10, 2010 4:58 am 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
Thanks, it works for one side (Many-to-One) side (in Auditlog.hbm.xml)


but how to do it in another side(One-to-Many) side(in Cancellation.hbm.xml)?

Do you have any hints?


Top
 Profile  
 
 Post subject: Re: How to create Many to One assocation where no foreign key
PostPosted: Wed Mar 10, 2010 6:03 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
What about using a 'where' condition in the mapping? Something like this:

Code:
<set name="auditlog" where="bussinessname = 'Cancellation' " inverse="true" lazy="true">
        <key column="businessid" not-null="true"/>
        <one-to-many class="Auditlog"/>
    </set>


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