-->
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: How to reach the pojo of a field (Foreign Key)
PostPosted: Mon Sep 17, 2007 9:20 am 
Newbie

Joined: Sun Apr 15, 2007 4:29 pm
Posts: 7
Hibernate version:hibernatetools-3.2.beta10

Company {
Long id; // PK
Stirng name;
List employeeList;
Employee {
Long id; // PK
Company company;
}

Can I reach the identifier of the company field in the template of Employee?

I need the identifiers of the FK's in a POJO.

Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 3:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I'm not sure what you are asking about, but look in the template code on how we access various relationships; that should give you a hint on what you want to do.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 3:33 am 
Newbie

Joined: Sun Apr 15, 2007 4:29 pm
Posts: 7
max wrote:
I'm not sure what you are asking about, but look in the template code on how we access various relationships; that should give you a hint on what you want to do.


I need to get the POJO of a field.

<#foreach field in pojo.getAllPropertiesIterator()>
<#if c2h.isManyToOne(field)>
${dochelper.getComponentPOJO(property).identifierProperty}
</#if>
</#foreach>

is it more clear? But it throws an exception.

org.hibernate.tool.hbm2x.ExporterException: Error while processing template form.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:253)
at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplateProducer.java:67)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:97)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.java:146)
at org.appfuse.tool.AppFuseExporter$1.exportPOJO(AppFuseExporter.java:216)
at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(GenericExporter.java:135)
at org.hibernate.tool.hbm2x.GenericExporter$2.process(GenericExporter.java:41)
at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java:126)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
at org.appfuse.tool.AppFuseExporter.generateWeb(AppFuseExporter.java:160)
at org.appfuse.tool.AppFuseExporter.doStart(AppFuseExporter.java:52)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
at org.appfuse.mojo.HibernateExporterMojo.doExecute(HibernateExporterMojo.java:228)
at org.appfuse.mojo.exporter.AppFuseGeneratorMojo.doExecute(AppFuseGeneratorMojo.java:251)
at org.appfuse.mojo.HibernateExporterMojo.execute(HibernateExporterMojo.java:138)
at org.appfuse.mojo.exporter.AppFuseGeneratorMojo.execute(AppFuseGeneratorMojo.java:204)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:443)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:493)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:463)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:280)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: freemarker.template.TemplateModelException: Method public org.hibernate.tool.hbm2x.pojo.POJOClass org.hibernate.tool.hbm2x.doc.DocHelper.getComponentPOJO(org.hibernate.mapping.Property) threw an exception when invoked on org.hibernate.tool.hbm2x.doc.DocHelper@1edcd24
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:136)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:74)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:160)
at freemarker.core.Environment.visit(Environment.java:351)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:95)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:160)
at freemarker.core.Environment.visit(Environment.java:351)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:95)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:231)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:247)
... 34 more
Caused by: java.lang.NullPointerException
at org.hibernate.tool.hbm2x.doc.DocHelper.getComponentPOJO(DocHelper.java:495)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:583)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:113)
... 60 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 26, 2007 4:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
don't call componentPojo on something that is not an component.

Unfortuantely I don't think I've ever needed to do this directly from a template so i don't have a shortcut method for it.

c2h.getSafeHibernateTypeName(property) will give you the string for that type (which might or might not be an actual entity in the general case)

The only way is then to add your own util class to digg it out and use code like the above to get it and use Configuration to look up the entity and create a Pojo from it.

_________________
Max
Don't forget to rate


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.