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: POJO Generation & getReferencedEntityName() & OneToM
PostPosted: Tue Sep 26, 2006 2:33 am 
Newbie

Joined: Fri Feb 17, 2006 6:02 am
Posts: 6
Hello,

I'm using Hibernate 3.0 beta2 with hbn-tools.


I'm generating code and i have made very heavy modifications to velocity templates.

I have tables:

A - ID
B - AID, A2ID

B - two columns from B references to same (lookup)table. don't ask why; original database designer fucked things up.

When code is generated in table B, ${pojo.getPropertyName($property)} returns BByAid, and BByA2id.

When code is generated in table A, ${property.getValue().getElement().getReferencedEntityName()} returns B.
My problem is that when code is generated in A, i NEED to know BByAid, and BByA2id!! Maybe i can get them out of a.hbn.xml????




Code:
<set name="BsForA" inverse="true">
            <key>
                <column name="AID" precision="22" scale="0" />
            </key>
            <one-to-many class="B" />
        </set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 5:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I assume what you are looking for is a way to get the "other" side of an association, correct ?

Unfortnately i haven't implemented the mechanics for that yet, so if you need it you have to look for it directly in the Configuration object.

You bascially need to scan the other sides properties and find the association that has the "matching" columns/types.

If you implement it I would appreciate if you contribute it back so others can benefit from it too.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 6:44 am 
Newbie

Joined: Fri Feb 17, 2006 6:02 am
Posts: 6

NOTE! This is not tested yet. It's a BIG glue. This just for testing purposes only!



Code:

#set( $isAdded = "false" )
   #foreach($property in $pojo.getAllPropertiesIterator())   
    #if($c2h.isOneToMany($property))
     #foreach($temp in $property.getValue().getElement().getAssociatedClass().getTable().getForeignKeyIterator())
      #if($temp.getReferencedEntityName() == $pojo.getDeclarationName())
       #foreach($fk in $temp.getColumns())

         #if($isAdded == "false")
String name = "$pojo.getDeclarationName()By" + "${fk.name}".toLowerCase().substring(0,1).toUpperCase());
   #end
   #end
   #end
   #end
   #set( $isAdded = "true" )
   #end
   #end



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.