-->
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: hbm2ddl with composite id needs pojo classes
PostPosted: Fri Nov 24, 2006 9:33 am 
Newbie

Joined: Fri Nov 24, 2006 9:03 am
Posts: 2
Hi,
I'm using hbm2ddl programmatically in a customized eclipse plugin. This works great for simple mappings. As soon as composite id's are involved in the mappings, hbm2ddl uses cglib which tries to call the POJO itself. This results in a MappingException (Component Class not found) and originally in a ClassNotFoundException.

Obviously it would be a solution to add the POJO class to the plugin classpath. But this is not that easy since multiple projects would be necessary in the classpath.

Anyway, I wonder why hbm2ddl needs the POJO classes since it seems as if all information needed to generate the ddl script is available in the mapping file.

Is there a way to configure hbm2ddl not to use the POJO classes?

Thanks in advance!
Thomas


Hibernate version: 3.1.3

Example-Mapping:

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>
    <class name="ch.edoras.standard.dms.filestore.model.FileMetaData" table="DMS_FILE_META_DATA" lazy="false">
       
      <composite-id>
           <key-property name="id" column="ID" type="long"/>
           <key-property name="versionNumber" column="version_number" type="int"/>
        </composite-id>

        <property name="createdAt" column="CREATED_AT" type="timestamp" length="20" />
        <property name="creationUser" column="CREATION_USER" type="string" length="20" />
        <property name="lastVersionIdentifier" column="LAST_VERSION_IDENTIFIER" type="boolean" length="20" not-null="true" />
        <property name="modifiedAt" column="MODIFIED_AT" type="timestamp" length="20" />
        <property name="modificationUser" column="MODIFICATION_USER" type="string" length="20" />
        <property name="fileExtension" column="FILE_EXTENSION" type="string" length="20" />
        <property name="fileId" column="FILE_ID" type="string" length="20" />
        <property name="fileName" column="FILE_NAME" type="string" length="20" />
        <property name="fileSize" column="FILE_SIZE" type="long" length="20" />
        <property name="fileComments" column="FILE_COMMENTS" type="string" length="20" />
        <property name="documentInfo" column="DOCUMENT_INFO" type="string" length="20" />
        <property name="keywords" column="KEYWORDS" type="string" length="20" />
        <property name="category" column="CATEGORY" type="string" length="20" />
        <property name="compressedFileInfo" column="COMPRESSED_FILE_INFO" type="string" />
    </class>
</hibernate-mapping>


Stack-Trace:

Code:
Caused by: org.hibernate.MappingException: component class not found: ch.edoras.standard.dms.filestore.model.FileMetaData
at org.hibernate.mapping.Component.getComponentClass(Component.java:105)
at org.hibernate.tuple.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:155)
at org.hibernate.tuple.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:40)
at org.hibernate.tuple.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:43)
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:91)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:59)
at edoras.tools.edsmm.sql.SqlGenerator.generate(SqlGenerator.java:109)
at edoras.tools.edsmm.actions.GenerateSqlAction.doGenerate(GenerateSqlAction.java:156)
at edoras.tools.edsmm.actions.GenerateSqlAction.access$0(GenerateSqlAction.java:153)
at edoras.tools.edsmm.actions.GenerateSqlAction$SqlWorkspaceModifyOperation.execute(GenerateSqlAction.java:233)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:98)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1721)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:110)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Caused by: java.lang.ClassNotFoundException: ch.edoras.standard.dms.filestore.model.FileMetaData
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:405)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:350)
at org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(AbstractClassLoader.java:78)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.mapping.Component.getComponentClass(Component.java:102)
... 18 more
Root exception:
org.hibernate.MappingException: component class not found: ch.edoras.standard.dms.filestore.model.FileMetaData
at org.hibernate.mapping.Component.getComponentClass(Component.java:105)
at org.hibernate.tuple.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:155)
at org.hibernate.tuple.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:40)
at org.hibernate.tuple.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:43)
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:91)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:59)
at edoras.tools.edsmm.sql.SqlGenerator.generate(SqlGenerator.java:109)
at edoras.tools.edsmm.actions.GenerateSqlAction.doGenerate(GenerateSqlAction.java:156)
at edoras.tools.edsmm.actions.GenerateSqlAction.access$0(GenerateSqlAction.java:153)
at edoras.tools.edsmm.actions.GenerateSqlAction$SqlWorkspaceModifyOperation.execute(GenerateSqlAction.java:233)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:98)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1721)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:110)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Caused by: java.lang.ClassNotFoundException: ch.edoras.standard.dms.filestore.model.FileMetaData
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:405)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:350)
at org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(AbstractClassLoader.java:78)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.mapping.Component.getComponentClass(Component.java:102)
... 18 more



Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 9:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
classes are needed if you don't specify all types in mapping because how else could it gets its type information.

But anyway use buddy classloading to circumvene this issue.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 9:54 am 
Newbie

Joined: Fri Nov 24, 2006 9:03 am
Posts: 2
max wrote:
classes are needed if you don't specify all types in mapping because how else could it gets its type information.

But anyway use buddy classloading to circumvene this issue.


Thanks for your fast response! But to mee it seems as if for all mappings the type is defined. What am I missing?

Buddy classloading seems also not to be a solution for my problem. As far as I understood, buddy classloading ist for inter plugin classloading only. My POJO classes will never be located in a plugin, since my plugin is generating first the POJO, then the hibernate mapping and finally the DDL file. And all three files get generated on the fly into an existing java project in the workspace.

Still any idea?
Thanks!


Top
 Profile  
 
 Post subject: Re: hbm2ddl with composite id needs pojo classes
PostPosted: Tue May 17, 2011 9:38 am 
Newbie

Joined: Fri May 21, 2010 8:53 pm
Posts: 8
Was there ever a resolution to this? I'm not exactly a Hibernate wizard, and I don't know what buddy classloading is, so at the moment I'm unable to follow the recommended advice.

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="com.blah">
    <class name="DataWarehousePoint" table="data_warehouse_points" mutable="false">
        <composite-id
                name="bdwpPrimaryKey"
                class="com.blah.DataWarehousePointPrimaryKey" >
            <key-property name="dataPointId" column="data_point_id" type="integer" />
            <key-property name="outputStatisticsId" column="output_statistics_id" type="integer" />
        </composite-id>
    <!-- rest of mapping here -->
    </class>
</hibernate-mapping>


And here is the result:

Code:
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl (default-cli) on project blah: Execution default-cli of goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl failed: component class not found: DataWarehousePointsId -> [Help 1]


Please assist, if you know of a possible course of action! Thanks!


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.