-->
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: programmatically add association to mapping
PostPosted: Tue Apr 06, 2010 10:40 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
We want to split our product into several components that the client can buy independently of each other. Nevertheless associations between the involved entities should be bidirectional. Let's say we have a Client Entity in our base component. We want to have bidirectional associations to this Entity from independent entities, like: CarShop.getClient(), Museum.getClient(), where CarShop and Museum don't know of each other's existence.

What's the best practice to achieve such modularity?
One approach I can see is to have all possible associations in the pojos and "activate" the possible ones upon startup in the mapping xml.

Another approach may be to modify the way hibernate discovers the mappings and add our own extra associations programmatically.

I've found some descriptions on how to add simple fields using a Map, but I haven't found a resource for adding associations and I am not sure what I have to change in AnnotationConfiguration or Configuration.


Top
 Profile  
 
 Post subject: Re: programmatically add association to mapping
PostPosted: Tue Apr 06, 2010 11:48 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
Ok, after reading this blog entry:
http://out-println.blogspot.com/2010/01/hibernate-disabling-all-lazy.html

I've decided to do something along these lines:
Code:
   private static void addInverserAssociationDirection(AnnotationConfiguration annotationConfig){
      PersistentClass p = annotationConfig.getClassMapping("E");
      
      Property prop = new Property();
      // TODO set attributes
      
      OneToOne oto = new OneToOne(p.getTable(),p);
      // TODO set attributes
      prop.setValue(oto);
      
      p.addProperty(prop);
   }


I'll report back on how it went.


Top
 Profile  
 
 Post subject: Re: programmatically add association to mapping
PostPosted: Wed Apr 07, 2010 11:34 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
Ok, I've managed to figure out what attributes to set how, but the problem is now to write a custom PropertyAccessor that does not need a field in the pojo. I've hacked something but I'm still at a loss how to make hibernate use my custom propertyaccessor.


Top
 Profile  
 
 Post subject: Re: programmatically add association to mapping
PostPosted: Thu Apr 08, 2010 5:59 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
Managed to do that too, now I'm struggling to do the same thing for OneToMany assocations. The Problem is that this isn't a simpleValue anymore and I'll have to figure out a way to get my role->collection mapping in the MappingsImpl.


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.