-->
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.  [ 9 posts ] 
Author Message
 Post subject: Multiple mapping with a single column
PostPosted: Thu May 03, 2007 3:31 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
Hi Hbm Users,

I need urgent help. I'm trying to do mapping "many-to-one" with a single column to different object.
Please tell me its doable or not
Help me

Thanks in advance

-Viks

_________________
get hibernate & get addicted


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 3:49 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
Yes. Here is an example.
<many-to-one name="objectOne" column="ref_id" />
<many-to-one name="objectTwo" column="ref_id" insert="false" update="false"/>


Here, we are forced to make atleast one association 'read-only'.
-----------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 5:38 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
--->


Last edited by vforvikash on Thu May 03, 2007 5:43 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 5:40 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
Hi Hbm Users,

Thanks for your reply Pramod. But still i'm in problem. I've even tested yr way.

<class name="UserRoles">
.
.
.

<many-to-one name="roleOfTypeSubscriberSponsor" column="entity_id" cascade="all" class="net.subscriber.SubscriberSponsor" not-found="ignore"/>
<many-to-one name="roleOfTypeMentor" column="entity_id" cascade="all" class="net.mentor.Mentor" not-found="ignore" insert="false" update="false"/>
<many-to-one name="roleOfTypeMonitor" column="entity_id" cascade="all" class="net.monitor.Monitor" not-found="ignore" insert="false" update="false"/>
<many-to-one name="roleOfTypeCorporateSponsor" column="entity_id" cascade="all" class="net.corporatesponsor.CorporateSponsor" not-found="ignore" insert="false" update="false"/>
</class>


My relationship is like the above - so a single column entity_id will map to different objects.
Its like a user can me of any kind. So entity_id will be a foreign key for different table.

Please help me out

-Vikash

_________________
get hibernate & get addicted


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 6:00 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
pramodkp wrote:
Hi,
Yes. Here is an example.
<many-to-one name="objectOne" column="ref_id" />
<many-to-one name="objectTwo" column="ref_id" insert="false" update="false"/>


Here, we are forced to make atleast one association 'read-only'.
-----------------------------------------
Rate the reply if you find it helpful






Thanks for your reply Pramod. But still i'm in problem. I've even tested yr way.

<class name="UserRoles">
.
.
.

<many-to-one name="roleOfTypeSubscriberSponsor" column="entity_id" cascade="all" class="net.subscriber.SubscriberSponsor" not-found="ignore"/>
<many-to-one name="roleOfTypeMentor" column="entity_id" cascade="all" class="net.mentor.Mentor" not-found="ignore" insert="false" update="false"/>
<many-to-one name="roleOfTypeMonitor" column="entity_id" cascade="all" class="net.monitor.Monitor" not-found="ignore" insert="false" update="false"/>
<many-to-one name="roleOfTypeCorporateSponsor" column="entity_id" cascade="all" class="net.corporatesponsor.CorporateSponsor" not-found="ignore" insert="false" update="false"/>
</class>


My relationship is like the above - so a single column entity_id will map to different objects.
Its like a user can me of any kind. So entity_id will be a foreign key for different table.

Please help me out

-Vikash

_________________
get hibernate & get addicted


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 6:03 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi Vikas Kaushik,
I am unable to get your problem.
Are you getting exceptions ?
What do you need from the mappings ?
What is it that you wanted to achieve, but could not, from the above mappings ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 6:08 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
pramodkp wrote:
Hi Vikas Kaushik,
I am unable to get your problem.
Are you getting exceptions ?
What do you need from the mappings ?
What is it that you wanted to achieve, but could not, from the above mappings ?


Hi Pramod,

I'm having a UserRole object which is associated with User 1-1.
And the UserRole is associated with different type of Objects with 0-1 from same column entityId( which is connecting to different Entities like Programmer/QA/Analyser).


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 7:56 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi Vikas Kaushik,
I understand the scenario as follows. ( tables )
USER:
id:
name:.....
USER_ROLE:
id:
entity_id: ( column central to all mapping )
otherAttributes....
MENTOR:
id:
attributes....
SPONSOR:
id:
attributes.....

Relationships:
USER.id :: USER_ROLE.entity_id :: MENTOR.id :: SPONSOR.id relate each other. ( equality )


Requirement:
i) UserRole contains Mentor, Sponsor ... objects.
ii) We need to navigate from role to related objects.


If I get them right ( you can correct me If I have missed anything ), I am not sure why the previous mapping did not solve the problem.
Here is another alternative with no restrictions like (insert="false", update="false")

<class name="UserRole">
<id name="id">......</id>
<many-to-one name="mentor" >
<formula>entity_id </formula>
</many-to-one>
<many-to-one name="sponsor" >
<formula>entity_id </formula>
</many-to-one>
<one-to-one name="user">
<formula>entity_id </formula>
</one-to-one>
</class>

and have id as the key in all other mapping files.

---------------------------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 8:39 am 
Newbie

Joined: Fri Mar 03, 2006 11:03 am
Posts: 19
Location: India
pramodkp wrote:
Hi Vikas Kaushik,
I understand the scenario as follows. ( tables )
USER:
id:
name:.....
USER_ROLE:
id:
entity_id: ( column central to all mapping )
otherAttributes....
MENTOR:
id:
attributes....
SPONSOR:
id:
attributes.....

Relationships:
USER.id :: USER_ROLE.entity_id :: MENTOR.id :: SPONSOR.id relate each other. ( equality )


Requirement:
i) UserRole contains Mentor, Sponsor ... objects.
ii) We need to navigate from role to related objects.


If I get them right ( you can correct me If I have missed anything ), I am not sure why the previous mapping did not solve the problem.
Here is another alternative with no restrictions like (insert="false", update="false")

<class name="UserRole">
<id name="id">......</id>
<many-to-one name="mentor" >
<formula>entity_id </formula>
</many-to-one>
<many-to-one name="sponsor" >
<formula>entity_id </formula>
</many-to-one>
<one-to-one name="user">
<formula>entity_id </formula>
</one-to-one>
</class>

and have id as the key in all other mapping files.

---------------------------------------------------------------------
Rate the reply if you find it helpful



hurrrryyyy.....you are awesome.
It solves my problem. Thanks a lot Pramod

-Vikash


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