-->
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.  [ 2 posts ] 
Author Message
 Post subject: Creating composite id with XDoclet for hibernate
PostPosted: Thu Apr 08, 2004 6:24 am 
Newbie

Joined: Tue Mar 09, 2004 11:24 am
Posts: 6
Hello,

I want to generate my hbm.xml file with XDoclet. I want to use a composite id for my RightTO class.

My implementation of the RightTO class looks like this:

Code:
/*
* Created on Apr 6, 2004
* By beva
*
* History
* Date   User   Comment
* ------  ------  ---------------
* Apr 6, 2004   beva   Initial
*
*/
package be.sofico.kiteserver.resource.common.system.rightmanagement;

import java.io.Serializable;

import be.sofico.kiteserver.resource.common.system.usermanagement.UserRoleTO;
import be.sofico.kiteserver.util.BaseTO;

/**
* @author beva
* Class that represents a right in Kite.
* Users with certain roles have the right to execute certain actions.
*
* @hibernate.class table="RIGHTS"
*/
public class RightTO extends BaseTO implements Serializable{
   private ActionTO action;
   private UserRoleTO userRole;
   
   /**
    * @hibernate.id type="be.sofico.kiteserver.util.compositeAttribute.RightType"
    * @hibernate.many-to-one column="ACTION_ID"  class="be.sofico.kiteserver.resource.common.system.rightmanagement.ActionTO"
    * @return
    */
   public ActionTO getAction() {
      return action;
   }
   
   /**
    * @hibernate.many-to-one column="USERROLE_ID" class="be.sofico.kiteserver.resource.common.system.usermanagement.UserRoleTO"
    * @return
    */
   public UserRoleTO getUserRole() {
      return userRole;
   }

   /**
    * @param i
    */
   public void setAction(ActionTO i) {
      action = i;
   }

   /**
    * @param i
    */
   public void setUserRole(UserRoleTO i) {
      userRole = i;
   }
}


The type i used for RightTO looks like this:
Code:
public class RightType implements CompositeUserType {
   
   /**
    * Get the property names of the Weight class
    */
   public String[] getPropertyNames() {
      // Return the values of the datamembers in the Weight class
      return new String[]{"action","userRole"};
   }
   /**
    * Get the types of the columns to which the properties are written
    */
   public Type[] getPropertyTypes() {
      return new Type[]{ Hibernate.OBJECT, Hibernate.OBJECT };
   }
   /**
    * Get the value of a property
    */
   public Object getPropertyValue(Object component, int property) {
      RightTO rightTO = ((RightTO) component);
      if( property == 0 ){
         return rightTO.getAction();
      }
      if( property == 1 ){
         return rightTO.getUserRole();
      }
      return null;
   }
   /**
    * Set the value of a property
    */
   public void setPropertyValue(Object component, int property, Object value) throws HibernateException {
      RightTO rightTO = (RightTO) component;
      if(property == 0)
      {
         rightTO.setAction((ActionTO) value);
      }
      if(property == 1)
      {
         rightTO.setUserRole((UserRoleTO) value);
      }
   }
   /**
    * Return the class of the type
    */
   public Class returnedClass() {
      return RightTO.class;
   }
   public boolean equals(Object x, Object y) throws HibernateException {
      return x.equals(y);
   }
   // Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.
   public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
      ActionTO actionTO = (ActionTO) Hibernate.OBJECT.nullSafeGet(rs,names[0],session,owner);
      UserRoleTO userRoleTO =  (UserRoleTO) Hibernate.OBJECT.nullSafeGet(rs, names[1],session,owner);
      RightDAO rightDAO = new RightDAO();
      RightTO rightTO = rightDAO.getNewRight();
      rightTO.setAction(actionTO);
      rightTO.setUserRole(userRoleTO);
      return ( actionTO==null && userRoleTO==null ) ? null :
      rightTO ;
   }
   //  Write an instance of the mapped class to a prepared statement.
   public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
      ActionTO actionTO = ((RightTO) value).getAction();

      UserRoleTO userRoleTO = ((RightTO) value).getUserRole();

      Hibernate.OBJECT.nullSafeSet(st, actionTO, index, session);
      Hibernate.OBJECT.nullSafeSet(st, userRoleTO, index+1, session);
   }
   /**
    * Make a deep copy of an object
    */
   public Object deepCopy(Object value) throws HibernateException {
      if ( value == null) return null;
      RightTO rightTO = (RightTO) value;
      RightDAO rightDAO = new RightDAO();
      RightTO copy = rightDAO.getNewRight();      
      copy.setAction(rightTO.getAction());
      copy.setUserRole(rightTO.getUserRole());
      return copy;
   }
   public boolean isMutable() {
      return true;
   }
   public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException {
      return (Serializable) deepCopy(value);
   }
   public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException {
      return (Serializable) deepCopy(cached);
   }


}


The ActionTO and UserRoleTO just have an regular id that is generated and uses increment as generator class.

When i try to generate the RightTO.hbm.xml file, i get the following error:

Code:
[hibernatedoclet] xdoclet.template.TemplateException: Invoking method in class xdoclet.modules.hibernate.HibernateTagsHandler failed: ifHasCompositeId, line=107 of template file: jar:file:/kite/eclipse/plugins/com.objectlearn.jdt.j2ee/xdoclet/xdoclet-hibernate-module-1.2b4.jar!/xdoclet/modules/hibernate/resources/hibernate.xdt, exception: null
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:542)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:927)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:894)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:434)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:333)
[hibernatedoclet]    at xdoclet.template.TemplateEngine.start(TemplateEngine.java:382)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:559)
[hibernatedoclet]    at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:765)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:665)
[hibernatedoclet]    at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:592)
[hibernatedoclet]    at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:196)
[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:458)
[hibernatedoclet]    at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:95)
[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.apache.tools.ant.taskdefs.Ant.execute(Ant.java:397)
[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.apache.tools.ant.Project.executeTargets(Project.java:1255)
[hibernatedoclet]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:569)
[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(NativeMethodAccessorImpl.java:39)
[hibernatedoclet]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatedoclet]    at java.lang.reflect.Method.invoke(Method.java:324)
[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(Thread.java:534)


Has anyone had this problem before?

And how did you solve it?

I hope that someone got the solution. It would be great.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 7:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://forum.hibernate.org/viewtopic.ph ... ht=xdoclet


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