[Hibernate-JIRA] Created: (HBX-1059) generating with generic hbmtemplate and maven 1.1
by Nicolas Andres (JIRA)
generating with generic hbmtemplate and maven 1.1
--------------------------------------------------
Key: HBX-1059
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1059
Project: Hibernate Tools
Issue Type: Improvement
Components: datagen
Affects Versions: 3.2.beta11
Environment: hibernate 3.2.6, maven 1.1, ant 1.6.5
Reporter: Nicolas Andres
Priority: Blocker
There is a problem referencing the freemarker templates when using maven 1.1. The hibernate-tools.jar and freemarker.jar have to be referenced in the POM file with the tag <classloader>root</classloader> otherwise the classes are not found when executing the hbmtemplate task. The defined classpath (<ant:classpath>....) will be loaded by a different classloader (AntClassLoader) which has the root classloader as parent classloader. So, I do not see a way to reference the ftl templates in the ant:classpath.
Unfortunately, the freemarker templates can only be referenced relative to the classpath and not as absolute file names. Because maven does not support to load resources on the root classpath (unlike jars) it is not possible to use hibernate tools as shown below.
from project.xml:
<dependency>
<groupId>lgpl</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0b11</version>
<type>jar</type>
<properties>
<classloader>root</classloader>
<ejb.manifest.classpath>false</ejb.manifest.classpath>
</properties>
</dependency>
from maven.mxl:
<ant:taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
/>
<ant:hibernatetool destdir="${hibernate.gen.destdir}">
<ant:configuration configurationfile="${hibernate.cfg}" />
<ant:hbmtemplate template="hibernateDao.ftl" filepattern="{package-name}/{class-name}HibernateDao.java" />
<ant:classpath>
<ant:pathelement path="${basedir}/../src/main/resources"/>
</ant:classpath>
</ant:hibernatetool>
console:
Exception stack traces :
org.apache.maven.werkz.UnattainableGoalException: Unable to obtain goal [generate]
at org.apache.maven.werkz.Goal.fire(Goal.java:698)
at org.apache.maven.werkz.Goal.attain(Goal.java:623)
at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:712)
at org.apache.maven.MavenSession.attainGoals(MavenSession.java:265)
at org.apache.maven.cli.App.doMain(App.java:307)
at org.apache.maven.cli.App.main(App.java:217)
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:324)
at com.werken.forehead.Forehead.run(Forehead.java:551)
at com.werken.forehead.Forehead.main(Forehead.java:581)
Caused by: org.apache.commons.jelly.JellyTagException: file:/C:/Documents and Settings/s74342/IBM/rationalsdp7.0/workspace/eum-ejb/maven/maven.xml:57:56: <ant:hibernatetool> org.hibernate.tool.hbm2x.ExporterException: Error while processing template hibernateDao.ftl
at org.apache.commons.jelly.impl.TagScript.handleException(TagScript.java:681)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:262)
at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:83)
at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag.java:116)
at org.apache.maven.werkz.Goal.fire(Goal.java:691)
at org.apache.maven.werkz.Goal.attain(Goal.java:623)
at org.apache.maven.werkz.WerkzProject.attainGoal(WerkzProject.java:209)
at org.apache.maven.jelly.tags.werkz.MavenAttainGoalTag.doTag(MavenAttainGoalTag.java:115)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:250)
at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:83)
at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag.java:116)
at org.apache.maven.werkz.Goal.fire(Goal.java:691)
... 11 more
Caused by: org.hibernate.tool.hbm2x.ExporterException: Error while processing template hibernateDao.ftl
at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:226)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:189)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:195)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:250)
... 23 more
Caused by: org.hibernate.tool.hbm2x.ExporterException: Error while processing template hibernateDao.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:254)
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.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.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
... 26 more
Caused by: java.io.FileNotFoundException: Template hibernateDao.ftl not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:489)
at freemarker.template.Configuration.getTemplate(Configuration.java:452)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:250)
... 36 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years
[Hibernate-JIRA] Created: (ANN-676) Composite PK/FK and the alphabetical order of class names
by Immo Heikkinen (JIRA)
Composite PK/FK and the alphabetical order of class names
---------------------------------------------------------
Key: ANN-676
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-676
Project: Hibernate Annotations
Issue Type: Bug
Components: binder
Affects Versions: 3.3.0.ga
Environment: Hibernate Core 3.2.5.GA , Hibernate Annotations 3.3.0.GA, Sybase ASE 15
Reporter: Immo Heikkinen
Priority: Blocker
Attachments: TestCaseFailure.zip, TestCaseOK.zip
Original discussion on the user forum: http://forum.hibernate.org/viewtopic.php?t=980623
I am having trouble with composite primary/foreign keys and sequence of classes with bidirectional one-to-many relationship between them. I am getting strange annotation exception with annotations that seem to be perfectly ok.
My conclusion is that the name of classes need to be in alphabetical order, otherwise misleading exception about the number of columns is thrown.
Attachment TestCaseOK.zip contains sequence of three entity classes A, B and C, with bi-directional one-to-many association between them. This mapping works fine.
Attachment TestCaseFailure.zip contains the same classes, but B and C has been changed with each other (B has been renamed to C, and C has been renamed to B.) This mapping causes the following AnnotationException:
Caused by: org.hibernate.AnnotationException: A Foreign key refering C from B has the wrong number of column. should be 1
The reason for this seems to be the alphabetical order of the class names! Sequence A --> B --> C is fine but A --> C --> B is not.
If you use @Table to define the database table names, it is the table names that need to be in alphabetical order.
The same error can be also produced with @SecondaryTable in class/table that has composite PK. This case is more difficult since you cannot get rid of the exception, no matter how you name your classes or tables. I believe this is the same bug that appears in the comments of ANN-509 .
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years