-->
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.  [ 3 posts ] 
Author Message
 Post subject: Embedded Error durch composite-id
PostPosted: Tue May 05, 2009 3:58 am 
Newbie

Joined: Tue May 05, 2009 3:11 am
Posts: 3
Hallo,

ich habe ein Problem mit der Erzeugung von Zusammengesetzten Fremdschlüsseln mit composite-ids. Bei der Ausführung meines Ant-tasks mit Maven hbm2ddl wird ein Fehler geworfen das er eine Klasse nicht finden kann. Aber diese Klasse für den Zusammengesetzten Fremdschlüssel soll doch erst mit Hilfe von Hibernate erzeugt werden, oder muss ich die Klasse manuell an legen. Orientiere mich da dem Beispiel cave at emptor von Christian Bauer aus dem Buch "Java Persistence with Hibernate".

Vielleicht hab ich nur einen ganz blöden Fehler oder es funktioniert grundsätzlich nicht. Wäre super wenn mich jemand in die richtige Richtung bringen könnte.

Hier die Mapping-Datei:

Code:
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="testpackage" default-access="field">
  <class name="testpackage.testclass" table="TESTTABLE_T" mutable="false">

    <composite-id name="id" class="testclass$Id">
        <key-property name="roleId" access="field" column="ROLE_ID"/>
        <key-property name="permissionId" access="field" column="PERMISSION_ID"/>
    </composite-id>
   
    <property name="created"  column="CREATED"  type="timestamp" not-null="true"/>
   
     <many-to-one   name="role"
                    column="ROLE_ID"
                    not-null="true"
                    insert="false"
                    update="false"
                    foreign-key="FK_RTP_TO_ROLE"/>

    <many-to-one   name="permission"
                    column="PERMISSION_ID"
                    not-null="true"
                    insert="false"
                    update="false"
          foreign-key="FK_RTP_TO_PERMISSION"/>
    </class>
</hibernate-mapping>


Hier die Fehlermeldung (ant-task mit maven):

Code:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.InvalidMappingException: Could not parse mapping document from resource testpackage/testclass.hbm.xml
[hibernatetool] org.hibernate.MappingException: class testpackage.testclass$Id not found while looking for property: roleId
[hibernatetool] java.lang.ClassNotFoundException: testpackage.testclass$Id
[hibernatetool] A class were not found in the classpath of the Ant task.
[hibernatetool] Ensure that the classpath contains the classes needed for Hibernate and your code are in the classpath.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: org.hibernate.InvalidMappingException: Could not parse mapping document from resource testpackage/testclass.hbm.xml
testpackage.testclass$Id
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error executing ant tasks
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:703)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:540)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:519)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:371)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:332)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:181)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:356)
        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:597)
        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: org.apache.maven.plugin.MojoExecutionException: Error executing ant tasks
        at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:114)
        at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:678)
        ... 16 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource testpackage/testclass.hbm.xml
        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.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.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:108)
        ... 19 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource testpackage/testclass.hbm.xml
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:575)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1593)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1561)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1468)
        at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:96)
        at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
        at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.createExporter(Hbm2DDLExporterTask.java:51)
        at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        ... 23 more
Caused by: org.hibernate.MappingException: class testpackage.testclass$Id not found while looking for property: roleId
        at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
        at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:279)
        at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2171)
        at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1900)
        at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1723)
        at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:424)
        at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:338)
        at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
        at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
        at org.hibernate.cfg.Configuration.add(Configuration.java:675)
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:510)
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:572)
        ... 34 more
Caused by: java.lang.ClassNotFoundException: testpackage.testclass$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:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
        ... 45 more


Gruß,
Andreas


Top
 Profile  
 
 Post subject: Re: Embedded Error durch composite-id
PostPosted: Thu May 07, 2009 7:33 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Ich kann dir nichts zum Buch sagen, Fragen dazu kannst du im Book-Forum stellen. Aber normalerweise musst du die Id-Klassen auch selber schreiben. Ist ja sehr simpel: Die gleichen Attribute rein, die als PK dienen, getter-setter, fertig.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Embedded Error durch composite-id
PostPosted: Thu May 07, 2009 10:19 am 
Newbie

Joined: Tue May 05, 2009 3:11 am
Posts: 3
Kann man auch, aber ich gehe nach dem Ansatz, das ich mir aus hbm Dateien DDLs und Java Code generieren lasse. Das mit der composite-id ist eine scheinbar geläufige Sache. Zumindest wenn man sich den Core von Hibernate herunterlädt, kann man sehen das die in ihren Testfällen auch so anwenden. Aber danke für den Tipp.


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