-->
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: Composite-Id code Generation
PostPosted: Sun Apr 09, 2006 6:39 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Hi,

Does hbm2java supports composite-id?! We are using HibernateTools-3.1.0.beta4.
Code:
<hibernate-mapping package="com.mycompany.dal.entity">
    <meta attribute="use-in-tostring">true</meta>
    <meta attribute="use-in-equals">true</meta>
    <meta attribute="extends">com.mycompany.dal.entity.StandardEntity</meta>
    <class name="Role" table="user_roles">
        <composite-id name="id" class="Role$Id"> <!-- or RolePK none work! -->
            <key-property name="userName" type="string" column="user_name" length="15"/>
            <key-property name="roleName" type="string" column="role_name" length="15"/>
        </composite-id>
    </class>
</hibernate-mapping>


generates:
Code:
org.hibernate.MappingException: component class not found: com.mycompany.dal.entity.Role$Id
   at org.hibernate.mapping.Component.getComponentClass(Component.java:105)
   at org.hibernate.tuple.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:140)
   at org.hibernate.tuple.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:79)
   at org.hibernate.tuple.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:33)
   at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:126)
   at org.hibernate.mapping.Component.getType(Component.java:160)
   at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
   at org.hibernate.cfg.Configuration.iterateGenerators(Configuration.java:601)
   at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:712)
   at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:96)
   at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:64)
   at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:43)
   at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:143)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
   at org.apache.tools.ant.Task.perform(Task.java:364)
   at org.apache.tools.ant.Target.execute(Target.java:341)
   at org.apache.tools.ant.Target.performTasks(Target.java:369)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
   at org.apache.tools.ant.Main.runBuild(Main.java:668)
   at org.apache.tools.ant.Main.startAnt(Main.java:187)
   at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
   at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
   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 com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:16)
Caused by: java.lang.ClassNotFoundException: com.mycompany.dal.entity.Role$Id
   at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
   at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
   at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Class.java:164)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
   at org.hibernate.mapping.Component.getComponentClass(Component.java:102)
   ... 29 more


If we generate RolePk every think will go fine.

Any Idea?!

Regards,
Alireza Fattahi


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 10:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is schemaexport (hbm2ddl) that complains here.

my guess is that you are running hbm2java and hbm2ddl in one go which is pretty hard since you haven't compiled the classes yet which is needed for hbm2ddl.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: composite-id and hbm2java
PostPosted: Tue Apr 25, 2006 12:27 pm 
Newbie

Joined: Tue Apr 25, 2006 11:03 am
Posts: 1
Disregard! The mapping file below was correct after all.

I'm trying to generate Java source from .hbm.xml files using the Ant hibernatetool task. I'm using the latest Hibernate Tools (3.1 beta 5) with Hibernate 3.1. The hibernatetool/hbm2java utility has a problem with a mapping file with a composite-id. Here's the mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
  PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="domain.account">

  <class name="CustomerEmail" table="CUSTOMER_EMAILS">
    <composite-id>
      <key-many-to-one name="customer" column="CUSTOMER_ID"
        class="Customer" />
      <key-many-to-one name="email" column="EMAIL_ID"
        class="Email" />
    </composite-id>

    <property name="primary" column="PRIMARY" type="boolean" />
    <property name="billing" column="BILLING" type="boolean" />
    <property name="technical" column="TECHNICAL" type="boolean" />

  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 1:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...and what is the problem?

_________________
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.