-->
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: Templates: Get "other" property name of association?
PostPosted: Tue Mar 27, 2012 7:57 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I have a MASTER and a DETAIL table in an 1:n association.
Master.java has
Code:
private Set<Detail> details

Details.java has
Code:
private Master master

plus all the setters and getters one might expect; nothing surprising there.

I now want to generate different setters via Freemarker and PojoPropertyAccessors.ftl: Details#setMaster should also update the details set in the associated Master pojo, something like this (leaving out some code that checks for proxied state and such):
Code:
public void setMaster (Master master){
  this.master.getDetails ().remove (this);
  this.master = master;
  this.master.getDetails ().add (this);
}

Now my problem is: How can PojoPropertyAccessors.ftl find out the name of the "details" property?
I have spent half a week writing Freemarker dump code just to get a list of available properties and methods in c2h, property, property.type, and property.type.value, but nowhere do I find a way to get hold of the backlink property. Did I overlook something, or is that information indeed unavailable?


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Wed May 02, 2012 11:21 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
*bump*
Anybody got an idea?


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Mon May 21, 2012 5:01 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
*bump 2 to overtake the link spammers, grr*


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Mon Jun 04, 2012 7:58 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Another bump to overtake the spammers...


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Fri Aug 03, 2012 4:23 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
You are looking for the name of field with type Set<Master>?

1) get Master pojo (back_pojo) (you have cfg in context, so can obtain any PersistentClass+pojo)
2) iterate through through it properties
3) ${back_pojo.getJavaTypeName(field, true)} - if method returns expected type (Set<Master>) you have found the property (backProperty)
4)//this.master.getDetails ().remove (this);
this.${property.name}.get${back_pojo.getPropertyName(backProperty)}.remove(this);

Note, you can implement this logic in java class and attach it to be used in your template.


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Fri Aug 03, 2012 6:37 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Ah, thanks - better late than never I guess :-)

Yes I'm looking for the name of that field.
However, just checking the type isn't unique enough, we have a case or two where two tables have multiple 1:n relationships between them.


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Fri Aug 03, 2012 7:16 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
Don't read some posts because of the spammers :)


Top
 Profile  
 
 Post subject: Re: Templates: Get "other" property name of association?
PostPosted: Fri Aug 03, 2012 12:04 pm 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Feh. Put in some antispam software, there's enough available. Or have an admin remove the spam.
I'm under the impression that the whole project is underfunded.

Anyway. How do I deal with the ambiguities I'd have?


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.