-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: XDoclet, Composite Class how to?
PostPosted: Tue Mar 09, 2004 3:38 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Hi alls,
i'm still writing french docs and try to talk about many cases. For all my classes i use xdoclet without problem but ...
One of these is "using a class as composite identifier"

I'm working with doc http://www.hibernate.org/hib_docs/refer ... nents-s2-3

My example class is:
public abstract class Player {
private PlayerId id;
private String playerName;
private int age;
private School school;
....
}
PlayerId is the idClass
public class PlayerId implements Serializable{
private Integer playerNumber;
private Team team; // we have a many to one here .....
...
}

So what tag must i write on each of these classes?


David said this in another topic
"Composite IDs in XDoclet is only supported when using an external class for the key. So you will be able to XDoclet generate your mapping. Most of the Xdoclet markup is on the Keys Class, eg, the field properties. The persistant class will have the ID with property reference to the key class."

But i can't find some doc about this.... :(
Can someone help?

Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2004 8:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The Player domain object has a id xdoclet tag and an assigned property for the generator.
The Primary key object (PlayerId) has the usual property xdoclet tags for each of the fields for the compound key. Its the same as a normal property but xdoclet knows its a compound key since is use by the id field for the domain object.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 2:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Thanks David, i'll try it this night


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
sorry i don't have it

Code:
/**
* @author tony
* @hibernate.class  table="PLAYER"
*
*/
public class Player {
   private PlayerId id;

   /**
    * @return
    * @hibernate.id  generator-class="assigned"
    */
   public PlayerId getId() {
      return id;
   }

   /**
    * @param id
    */
   public void setId(PlayerId id) {
      this.id = id;
   }
...
}


/**
* @author tony
* @hibernate.class  table="PLAYER" --> i tried with or without this tag
*/
public class PlayerId implements Serializable{
   private Integer playerNumber;
   private Team team;

   
   /**
    * @return
    * @hibernate.property column="NUMBER"
    */
   public Integer getPlayerNumber() {
      return playerNumber;
   }

   /**
    * @param integer
    */
   public void setPlayerNumber(Integer integer) {
      playerNumber = integer;
   }

   /**
    * @return
    * @hibernate.many-to-one column="TEAM_ID" class="com.hibernateSample.bo.Team"
    */
   public Team getTeam() {
      return team;
   }

   /**
    * @param team
    */
   public void setTeam(Team team) {
      this.team = team;
   }

}





running xdoclet throws this exception:
Code:

Buildfile: C:\J2EE\eclipse\workspace\HibernateSample\WEB-INF\build.xml

generate:
[hibernatedoclet] log4j:WARN No appenders could be found for logger (xdoclet.util.Translator.getString).
[hibernatedoclet] log4j:WARN Please initialize the log4j system properly.
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.Team.
[hibernatedoclet]    com.hibernateSample.bo.Team
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.School.
[hibernatedoclet]    com.hibernateSample.bo.School
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.PlayerId.
[hibernatedoclet]    com.hibernateSample.bo.PlayerId
[hibernatedoclet] file:C:/J2EE/eclipse/workspace/HibernateSample/WEB-INF/build.xml:26: XDoclet failed.
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:467)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] Caused by: xdoclet.XDocletException: Class com.hibernateSample.bo.PlayerId misses ID property
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.hasCompositeId_Impl(HibernateTagsHandler.java:482)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.ifHasPrimitiveId(HibernateTagsHandler.java:153)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invoke(TemplateEngine.java:635)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:561)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    ... 15 more
[hibernatedoclet] --- Nested Exception ---
[hibernatedoclet] xdoclet.XDocletException: Class com.hibernateSample.bo.PlayerId misses ID property
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.hasCompositeId_Impl(HibernateTagsHandler.java:482)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.ifHasPrimitiveId(HibernateTagsHandler.java:153)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invoke(TemplateEngine.java:635)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:561)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] BUILD FAILED: file:C:/J2EE/eclipse/workspace/HibernateSample/WEB-INF/build.xml:26: Unexpected error
Total time: 2 seconds




Does XDoclet need equals & hashcode methods to generate hbm files?

Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 5:24 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
without @hibernate.class table="PLAYER" on PlayerId class,i've got this :

Code:

Buildfile: C:\J2EE\eclipse\workspace\HibernateSample\WEB-INF\build.xml

generate:
[hibernatedoclet] log4j:WARN No appenders could be found for logger (xdoclet.util.Translator.getString).
[hibernatedoclet] log4j:WARN Please initialize the log4j system properly.
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.Coach.
[hibernatedoclet]    com.hibernateSample.bo.Coach
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.Player.
[hibernatedoclet]    com.hibernateSample.bo.Player
[hibernatedoclet] xdoclet.template.TemplateException: Invoking method in class xdoclet.modules.hibernate.HibernateTagsHandler failed: ifHasCompositeId, line=107 of template file: jar:file:C:\J2EE\eclipse\workspace\HibernateSample\WEB-INF\lib\xdoclet\xdoclet-hibernate-module-1.2.jar!/xdoclet/modules/hibernate/resources/hibernate.xdt, exception: null
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:574)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] xdoclet.template.TemplateException: Invoking method in class xdoclet.modules.hibernate.HibernateTagsHandler failed: ifHasCompositeId, line=107 of template file: jar:file:C:\J2EE\eclipse\workspace\HibernateSample\WEB-INF\lib\xdoclet\xdoclet-hibernate-module-1.2.jar!/xdoclet/modules/hibernate/resources/hibernate.xdt, exception: null
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:574)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] file:C:/J2EE/eclipse/workspace/HibernateSample/WEB-INF/build.xml:26: XDoclet failed.
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:467)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] Caused by: xdoclet.XDocletException: Running XDoclet failed.
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:776)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    ... 15 more
[hibernatedoclet] --- Nested Exception ---
[hibernatedoclet] xdoclet.XDocletException: Running XDoclet failed.
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:776)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] BUILD FAILED: file:C:/J2EE/eclipse/workspace/HibernateSample/WEB-INF/build.xml:26: Unexpected error
Total time: 2 seconds


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 8:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Your have an unknown id error expection message (first posting). This is because a many-to-one in the key is not valid. You need to use a key-many-to-one xdoclet tag. Try it without the relationship first so you can see the hbm get generated then add the relationship. I always try to do simplest solution first when trying out new techniques so my confidence and knowledge builds up slowly. Its also easier to solve the problems as they crop up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 4:12 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
I'm doing the same thing as delpouve.
I have a Foo class which has a composite id of (foo_id, parent_id).
parent_id is the id for class Parent.

Code:
class Foo {
    FooID id;

    /**
     * @hibernate.id
     *       generator-class="assigned"
     */
    public FooID getId() { .. }

    ---o<--snip---
}

class FooID {
   Parent parent;
   Long fooId;

    /**
     * @hibernate.property
     *      column = "parent_id"
     *      not-null = "true"
     *
     *  @hibernate.many-to-one
     *      column = "parent_id"
     *      class = "com.raverun.Parent"
     */
   public Parent getParent() {
       return parent;
   }

   ----o<--- snip ---
}



The problem is that the database type for column parent_id is VARCHAR BINARY in the generated schema. See below:
Code:
create table Foo (
   foo_id BIGINT not null,
   parent_id VARCHAR(255) BINARY not null
     ---o<--- snip ---
}


I want it to be BIGINT (MySQL dialect). I looked at the xdt file and Xdoclet basically infers the type from the parent member. How can I make it to be of type BIGINT and still preserve the many-to-one relationship with Parent ?

Regards,

Alistair


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Your right - just double checked the Xdoclet markup and the plain many-to-one is correct (I avoid compound keys like death :-) ).

The hbm requires a ddl hint which can be added with a hibernate.column tag,
try:



Code:
...
     * @hibernate.property
     *      not-null = "true"
     *
     *  @hibernate.many-to-one
     *      class = "com.raverun.Parent"
     *
     *  @hibenate.column
     *      name="parent_id"
     *      sql-type="java.lang.BigInt"
...


You may have to fiddle to get this to work correctly but it should (I have not tried it) work. Alternatively, the many-to-one can go on the Parent property and update="false" and insert="false".


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:28 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
David,

You said you avoid composite keys like death !

What are the alternatives ? Do you suggest managing the constraints on the tables ourselves e.g. utilizing Interceptor? I'm currently using it to generate the schema for the tables.

Thanks

Alistair


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Where possible (not always an option) I don't ceate tables that use composite keys - thats all. So far I have not needed to make composite keys work for a production system using hibernate. Only time I use them is for testing out items for this forum or for Middlegen development work.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:52 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
David,

I'm very curious. Could you then share with us how you would model this domain ?

A Company has many Branches

It is a typical one-to-many relationship. A branch only belongs to one company.

The way I see it, the table for Branch needs to have a composite-key (company_id, branch_id).

Thanks for your thoughts.

Regards,

alistair

[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 3:03 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i don't understand

Code:

package com.hibernateSample.bo;

/**
* @author tony
* @hibernate.class  table="PLAYER"
*
*/
public class Player {
   private PlayerId id;
   private String playerName;
   private int age;
   private School school;

   
   /**
    *
    */
   public Player() {
   }

   /**
    * @return
    * @hibernate.property column="AGE"
    */
   public int getAge() {
      return age;
   }

   /**
    * @return
    * @hibernate.property column="NAME"
    */
   public String getPlayerName() {
      return playerName;
   }

   /**
    * @return
    * @hibernate.many-to-one column="SCHOOL_ID" class="com.hibernateSample.bo.School"
    */
   public School getSchool() {
      return school;
   }

   /**
    * @param i
    */
   public void setAge(int i) {
      age = i;
   }

   /**
    * @param string
    */
   public void setPlayerName(String string) {
      playerName = string;
   }

   /**
    * @param school
    */
   public void setSchool(School school) {
      this.school = school;
   }



   /**
    * @return
    * @hibernate.id  generator-class="assigned"
    */
   public PlayerId getId() {
      return id;
   }

   /**
    * @param id
    */
   public void setId(PlayerId id) {
      this.id = id;
   }

}


package com.hibernateSample.bo;

import java.io.Serializable;

/**
* @author tony
* @hibernate.class  table="PLAYER"
*/
public class PlayerId implements Serializable{
   private Integer playerNumber;
   private Team team;

   
   /**
    * @return
    * @hibernate.property column = "NUMBER"
    */
   public Integer getPlayerNumber() {
      return playerNumber;
   }

   /**
    * @param integer
    */
   public void setPlayerNumber(Integer integer) {
      playerNumber = integer;
   }

   /**
    * @return
    * @hibernate.property column = "TEAM_ID"
     * @hibernate.many-to-one column = "parent_id" class="com.hibernateSample.bo.Team"
    */
   public Team getTeam() {
      return team;
   }

   /**
    * @param team
    */
   public void setTeam(Team team) {
      this.team = team;
   }

}




and i have this:
Code:

Buildfile: C:\J2EE\eclipse\workspace\HibernateSample\WEB-INF\build.xml

generate:
[hibernatedoclet] log4j:WARN No appenders could be found for logger (xdoclet.util.Translator.getString).
[hibernatedoclet] log4j:WARN Please initialize the log4j system properly.
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.Team.
[hibernatedoclet]    com.hibernateSample.bo.Team
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.School.
[hibernatedoclet]    com.hibernateSample.bo.School
[hibernatedoclet] Generating mapping file for com.hibernateSample.bo.PlayerId.
[hibernatedoclet]    com.hibernateSample.bo.PlayerId
[hibernatedoclet] file:C:/J2EE/eclipse/workspace/HibernateSample/WEB-INF/build.xml:26: XDoclet failed.
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:467)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] Caused by: xdoclet.XDocletException: Class com.hibernateSample.bo.PlayerId misses ID property
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.hasCompositeId_Impl(HibernateTagsHandler.java:482)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.ifHasPrimitiveId(HibernateTagsHandler.java:153)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invoke(TemplateEngine.java:635)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:561)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    ... 15 more
[hibernatedoclet] --- Nested Exception ---
[hibernatedoclet] xdoclet.XDocletException: Class com.hibernateSample.bo.PlayerId misses ID property
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.hasCompositeId_Impl(HibernateTagsHandler.java:482)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateTagsHandler.ifHasPrimitiveId(HibernateTagsHandler.java:153)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invoke(TemplateEngine.java:635)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:561)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
[hibernatedoclet]    at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
[hibernatedoclet]    at xdoclet.XDocletMain.start(XDocletMain.java:48)
[hibernatedoclet]    at xdoclet.DocletTask.start(DocletTask.java:464)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
[hibernatedoclet]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[hibernatedoclet]    at org.apache.tools.ant.Task.perform(Task.java:341)
[hibernatedoclet]    at org.apache.tools.ant.Target.execute(Target.java:309)
[hibernatedoclet]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
[hibernatedoclet]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:571)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatedoclet]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Unknown Source)
[hibernatedoclet]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
[hibernatedoclet]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
[hibernatedoclet]    at java.lang.Thread.run(Unknown Source)
[hibernatedoclet] BUILD FAILED: file:C:/J2EE/eclipse/workspace/HibernateSample/WEB-INF/build.xml:26: Unexpected error
Total time: 3 seconds


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i've got it, in fact XDoclet really need equals or hashcode (or both??) method to generate mapping files... curious no?


For everybody that will try it here is a sample code (i know my hashcode method is not ok... lol)

Code:
package com.hibernateSample.bo;

/**
* @author tony
* @hibernate.class  table="PLAYER"
*
*/
public class Player {
   private PlayerId id;
   private String playerName;
   private int age;
   private School school;

   
   /**
    *
    */
   public Player() {
   }

   /**
    * @return
    * @hibernate.property column="AGE"
    */
   public int getAge() {
      return age;
   }

   /**
    * @return
    * @hibernate.property column="NAME"
    */
   public String getPlayerName() {
      return playerName;
   }

   /**
    * @return
    * @hibernate.many-to-one column="SCHOOL_ID" class="com.hibernateSample.bo.School"
    */
   public School getSchool() {
      return school;
   }

   /**
    * @param i
    */
   public void setAge(int i) {
      age = i;
   }

   /**
    * @param string
    */
   public void setPlayerName(String string) {
      playerName = string;
   }

   /**
    * @param school
    */
   public void setSchool(School school) {
      this.school = school;
   }



   /**
    * @return
    * @hibernate.id  generator-class="assigned"
    */
   public PlayerId getId() {
      return id;
   }

   /**
    * @param id
    */
   public void setId(PlayerId id) {
      this.id = id;
   }

}


//////////////////////////////////////////////////////


package com.hibernateSample.bo;

import java.io.Serializable;

/**
* @author tony
*
*/
public class PlayerId implements Serializable{
   private Integer playerNumber;
   private Team team;

   
   /**
    * @return
    * @hibernate.property
    */
   public Integer getPlayerNumber() {
      return playerNumber;
   }

   /**
    * @param integer
    */
   public void setPlayerNumber(Integer integer) {
      playerNumber = integer;
   }

   /**
    * @return
    * @hibernate.many-to-one
    */
   public Team getTeam() {
      return team;
   }

   /**
    * @param team
    */
   public void setTeam(Team team) {
      this.team = team;
   }
   
   public boolean equals(Object o)
   {
      if (o == null) {
         return false;
      }
      if (getClass().equals(o.getClass()) &&
         playerNumber.equals(((PlayerId) o).getPlayerNumber()) &&
         team.equals(((PlayerId) o).getTeam())
         ) {
         return true;
      }
      else {
         return false;
      }

   }

   public int hashCode()
   {
      return playerNumber.hashCode();
   }

}




Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 9:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
alistair wrote:
David,

I'm very curious. Could you then share with us how you would model this domain ?

A Company has many Branches

It is a typical one-to-many relationship. A branch only belongs to one company.

The way I see it, the table for Branch needs to have a composite-key (company_id, branch_id).

Thanks for your thoughts.

Regards,

alistair

[/quote]

No the branch table does not need a composite id and I would strongly recommend you don't use composite keys in this situation. It just needs a synthetic key (branch_id) and a foreign key (company_id).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 9:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Quote:
i've got it, in fact XDoclet really need equals or hashcode (or both??) method to generate mapping files... curious no?

Hmmm.... It is required for Hibernate to work with the composite ids but I would not have thought that it would be the case for XDoclet generation. There no connection between equals/hashcode with the mapping document. When I get a moment I will have to confirm this. In anycase, glad it is sorted - Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

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.