-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to map association specifying the target entity name?
PostPosted: Sun May 27, 2007 1:04 pm 
Newbie

Joined: Sun May 27, 2007 12:52 pm
Posts: 7
Hi,

I hava a class (named AccessMonitor) that is mapped twice in my application with two differents entity names (entities AccessMonitor_A and AccessMonitor_B), each one mapped to different tables. Here is a fragment of the hbm.xml file:

Code:
<hibernate-mapping>
    <class entity-name="AccessMonitor_A"
           name="accessmonitor.AccessMonitor"
           table="AccessMonitor_A">
        ...
    </class>
    <class entity-name="AccessMonitor_B"
           name="accessmonitor.AccessMonitor"
           table="AccessMonitor_B">
        ...
    </class>
</hibernate-mapping>



Many other classes of my application may have association with AccessMonitor. Let's say that class A has an association getAccessMonitor() which should map to entityname AccessMonitor_A and class B has has an association getAccessMonitor() which should map to entityname AccessMonitor_B.

Is there any way to setup this mappings with Hibernate 3?

Thanks,
Celso


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 27, 2007 1:20 pm 
Newbie

Joined: Tue May 08, 2007 12:25 am
Posts: 18
when you setup the association between your other objects and your accessmonitor make sure you specify the entity name again


<many-to-one name="AccessMonitor"
column="monitor_id"
entity-name="AccessMonitor_B"/>



hope this helps =)


Top
 Profile  
 
 Post subject: And using annotations?
PostPosted: Sun May 27, 2007 3:27 pm 
Newbie

Joined: Sun May 27, 2007 12:52 pm
Posts: 7
What about using annotations? Is there a way to map this with annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 27, 2007 3:36 pm 
Newbie

Joined: Tue May 08, 2007 12:25 am
Posts: 18
I have yet to start using annootations, however, i would assume you just specify the keyword "entity-name" in the annotation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 10:32 am 
Newbie

Joined: Sun May 27, 2007 12:52 pm
Posts: 7
imosquer wrote:
I have yet to start using annootations, however, i would assume you just specify the keyword "entity-name" in the annotation.



Unfortunatly the annotation @ManyToOne doesn't have the keyword entity-name :(

It does have an "targetEntity" keyword but it accepts only an Class object, which is not the case.

Anyways, thanks for your help, imosquer!

Does anybody else knows how to do this mapping using annotations?


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