-->
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.  [ 8 posts ] 
Author Message
 Post subject: How do I get "join table" in mapping file programm
PostPosted: Fri Apr 11, 2008 12:10 am 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
Hi,

I'm trying to generate mapping files from programmatically accessible (old) ORM information. Hibernate Tools helps me with generating hbm.xml files - I tweaked them so that I transform the old information into org.hibernate.mapping objects. I haven't yet found any reference on how to get the "join table" information. All I found is this code snippet in org.hibernate.cfg.HbmBinder:

Code:
...else if ( "join".equals( name ) ) {
   Join join = new Join();
   join.setPersistentClass( persistentClass );
   bindJoin( subnode, join, mappings, inheritedMetas );
   persistentClass.addJoin( join );
}

So apparently, "join" is mapped to org.hibernate.mapping.Join. Looking at HBMTagForValueVisitor I thought about extending it and implementing

Code:
public Object accept(Join join) {
   return "join";
}

But then again, Join doesn't implement the needed accept method and also doesn't implement Value, which is returned from Property.getValue (which is accessed in the Freemarker templates). Could somebody please guide me in the right direction on how to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 5:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
pc.getJoinIterator()

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 12:04 pm 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
Thanks, Max!

Some explanations for a probably simple question at the end...

This is what I got so far:

In build.xml:

Code:
<hbmtemplate template="my-mapping.hbm.ftl"
...

In my-mapping.hbm.ftl I have all that is in persistentclass.hbm.ftl plus:

Code:
<#foreach join in clazz.getJoinIterator()>
<#include "join.hbm.ftl"/>
</#foreach>


Now I'm not sure how to access the join in join.hbm.ftl. Looking at set.hbm.ftl and others, I noticed that the interpolation "property" is accessed - this is something that could teach me how to do it:

Code:
<set name="${property.name}"
...

I'm still puzzled because I don't see where "property" is set. The only place I found is in persistentclass.hbm.ftl:

Code:
<#foreach property in clazz.getUnjoinedPropertyIterator()>
<#if c2h.getTag(property)!="version" && c2h.getTag(property)!="timestamp">
<#include "${c2h.getTag(property)}.hbm.ftl"/>
</#if>
</#foreach>

So there you have a place where it is assigned (foreach property in ...), but it's in another template, not the template for the set. Are these variables somehow magically handed over between templates?
What I would like to be able to write in join.hbm.ftl is this:

Code:
<join
table="${join.getTable().getName()}"
inverse="${join.inverse?string}"
...

So how do I make the variable "join" known to the template join.hbm.ftl?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 6:53 pm 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
O.K., got it going now. Works like a charm :-)
Apparently the variable is simply handled like that. This is how it looks like now:

Code:
   <join
      table="${join.getTable().getName()}"
      inverse="${join.isInverse()?string}"
      optional="${join.isOptional()?string}"
      >
      <key>
       <#foreach column in join.getKey().getColumnIterator()>
         <#include "column.hbm.ftl">
       </#foreach>
     </key>
     <#foreach property in join.getPropertyIterator()>     
            <#include "many-to-one.hbm.ftl">
     </#foreach>
  </join>   


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 12, 2008 2:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Peter - that is usefull for others, could you submit it to jira as a patch ?

thanks

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 12, 2008 6:10 am 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
Max,

I'm not sure if this makes sense. After all, I tweaked Hibernate Tools so that Joins are added to the PersistentClass. I get this information from the old ORM metadata. As far as I know the standard Tools there is no place where Joins are added, so it's useless for the template trying to access them. I also don't know if and how this could be solved based only on information from the database.
Please correct me if I'm wrong, I'm always happy to learn :-)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 12, 2008 9:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you use annotations and want the equaivalent hbm.xml file then it would be usefull.

or when someone adds join support like you did for your own usecase it would also help.

reverse engineering is just one of the possible sources.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 13, 2008 2:18 am 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
Here it is: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1057


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