-->
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.  [ 10 posts ] 
Author Message
 Post subject: ClassNotFoundException using composite-id in hbm2dll
PostPosted: Thu Feb 28, 2008 8:05 am 
Newbie

Joined: Thu Feb 28, 2008 7:54 am
Posts: 5
Hello,

I'm using the latest Hibernate version (3.2.0). The hbm files used are created dynamically and hibernate generates the SQL scripts for different databases.

Everything works as expected except the composite-id elements, when using these elements Hibernate looks for the class (which does not exist) to check the existence of get and set methods for the composit-id elements and fails (the class is not found).

The example is as follows:

<hibernate-mapping>
<class name="MYCLASS" table="MYCLASS">
<!-- <id name="MYCLASSCODE" type="string" column="MYCLASSCODE" length="255">
<generator class="assigned"/>
</id> -->
<composite-id>
<key-property column="MYCLASSCODE" length="255" name="MYCLASSCODE" type="string"/>
</composite-id>
<property column="MYCLASSACCPOST" length="255" name="MYCLASSACCPOST" type="string"/>
<property column="MYCLASSACCPRE" length="255" name="MYCLASSACCPRE" type="string"/>
</class>

</hibernate-mapping>

When the "<composite-id..." is commented and the "<id... " is used, the sql is generated with no problems.

My questions are:
1) Does anyone know why the composite-id element requires the Java classes to be present? or is just a bug?
2) How this problem can be overcome?

Digging a bit I discovered that when the class exists with the proper set and get methods, the sql is generated fine. However I don't see why the class is required if all needed elements are specified on the hbm file.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 11:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
show the stacktrace, your description matches multiple possible causes.

If all type ifno is in the hbm.xml it should just work.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 4:46 am 
Newbie

Joined: Thu Feb 28, 2008 7:54 am
Posts: 5
Hi,
Here there is the full mapping and stack trace.

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 auto-import="true" schema="GREC">
   <class name="SYFI" table="SYFI">
      <composite-id>
         <key-property column="SYFICODI" length="255" name="SYFICODI" type="string"/>
      </composite-id>
      <property column="SYFIMIRAPROP" length="255" name="SYFIMIRAPROP" type="string"/>
      <property column="SYFIORDEN" length="255" name="SYFIORDEN" type="string"/>
      <property column="SYFINUMER" length="255" name="SYFINUMER" type="string"/>
   </class>
</hibernate-mapping>



[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[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.MappingException: component class not found: SYFI
[hibernatetool] java.lang.ClassNotFoundException: SYFI
[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 ar
e in the classpath.

BUILD FAILED
D:\ihg\codi\grec\migration\common_build.xml:139: org.hibernate.MappingException: component class not
found: SYFI
        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:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: org.hibernate.MappingException: component class not found: SYFI
        at org.hibernate.mapping.Component.getComponentClass(Component.java:104)
        at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:133)
        at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:43)
        at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:38)
        at org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:52)
        at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:50)
        at org.hibernate.mapping.Component.buildType(Component.java:152)
        at org.hibernate.mapping.Component.getType(Component.java:145)
        at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
        at org.hibernate.cfg.Configuration.iterateGenerators(Configuration.java:716)
        at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:827)
        at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:93)
        at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        ... 16 more
Caused by: java.lang.ClassNotFoundException: SYFI
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1383)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1324)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1072)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.mapping.Component.getComponentClass(Component.java:101)
        ... 30 more
--- Nested Exception ---
org.hibernate.MappingException: component class not found: SYFI
        at org.hibernate.mapping.Component.getComponentClass(Component.java:104)
        at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:133)
        at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:43)
        at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:38)
        at org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:52)
        at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:50)
        at org.hibernate.mapping.Component.buildType(Component.java:152)
        at org.hibernate.mapping.Component.getType(Component.java:145)
        at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
        at org.hibernate.cfg.Configuration.iterateGenerators(Configuration.java:716)
        at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:827)
        at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:93)
        at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.ClassNotFoundException: SYFI
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1383)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1324)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1072)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.mapping.Component.getComponentClass(Component.java:101)
        ... 30 more


Besides that, we digged a bit into the code and we hacked the class org.hibernate.tuple.component.ComponentMetamodel by commenting out the line 49:

tuplizerMapping = new ComponentEntityModeToTuplizerMapping( component );

With that change, the DDL generation works fine for a large number of entities (around 400) and as we don't have in mind to create Java classes, we use the modified class.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
1) are you sure you are using a recent version of hibernate tools/Hibernate core ? I can't reproduce this. If you are then please create a working testcase that fails and add to a jira.

2) If you are only using this for generating DDL, why don't you put the classes in the classpath so it can actually find the class ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 4:39 am 
Newbie

Joined: Thu Feb 28, 2008 7:54 am
Posts: 5
Hi,

The example still fails:

1) We are using the latest libraries, both Hibernate core and Hibernate tools
2) The hibernate mappings (hbm) are created dynamically from a file-storage-based application, no class is ever generated from the resulting mapping.

Perhaps the tool hbm2ddl is not intended to be use that way, and instead it's preferable to use hbm2java before creating the sql scripts?

We can create a jira entry if this can help.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 7:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
avives wrote:
1) We are using the latest libraries, both Hibernate core and Hibernate tools


Ok.

Quote:
2) The hibernate mappings (hbm) are created dynamically from a file-storage-based application, no class is ever generated from the resulting mapping.


And you don't even have any model classes available at build time or ?

Quote:
Perhaps the tool hbm2ddl is not intended to be use that way, and instead it's preferable to use hbm2java before creating the sql scripts?


Well, it should be possible but i've never heard about anyone needing to run hbm2ddl without having the classes available ?

Quote:
We can create a jira entry if this can help.


Yes, please.

btw. I noticed your mapping have only one column in your composite-id, why don't you just use <id> ? simpler and muuch better.

Thanks[/quote]

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 8:15 am 
Newbie

Joined: Thu Feb 28, 2008 7:54 am
Posts: 5
>And you don't even have any model classes available at build time or ?
No. We don't need the classes, we are using Hibernate as a middle-tier in-between a file storage system and a database (only talking about data model).

The think is the system we are mapping is dynamic, so a static mapping would be a nightmare to maintain. We have created code to create the hbm files based on the dynamic model and some hbm templates. After the hbm files are created the hbm2ddl is used to generate the create or update sql script.

So, no class for the mapping ever exists.


>Well, it should be possible but i've never heard about anyone needing to >run hbm2ddl without having the classes available ?

The system works perfectly fine but for the composite-id elements. Actually the sample is using a single-element composite-id just to simplify it, we really need multiple composite-id and are actually using them.


>Yes, please.

We will do that.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 8:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the issue is that to run hbm2ddl a SessionFactory needs to be created and without having the classes available (i assume you use some magic classloader) it is going to be tough (read: impossible)

hbm2java would work fine since it just needs a Configuration, not a full SessionFactory.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 8:50 am 
Newbie

Joined: Thu Feb 28, 2008 7:54 am
Posts: 5
Hi,

We are using all default hibernate configuration, no magic classloaders or anything similar. Perhaps my last explanation was too hurried and not clear enough, I'll try to be more precise...

We are using the 'middle-out' approach, where the hbm are used to generate classes or SQL scripts which don't exist previously. In our case we are not interested in the classes but just on the SQL scripts. As the classes don't exist we made up the classes names and we specify the 'type' on all properties. We found that whenever the type is not present the tool tries to load the class to figure out the property's type, this is solved just be adding a hibernate type to all properties.

However the composite-id does not follow that rule, all hbm that contain a composite-id component always try to load the class even if a type is correctly specified (it looks for setter and getters that it does not use when generating the SQL scripts, perhaps they are used in hbm2java).

By reading Hibernate in Action we understood that the approach described before should work without creating a java class.

Also, by commenting one line on the class org.hibernate.tuple.component.ComponentMetamodel everything works fine and the SQL is created without errors, this makes us guess that the problem might not be on the hbm2ddl tool but on the way the components are handled internally.

If the approach followed by us is correct, the error found could be a bug and we will open a jira entry.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 9:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well the problem is that it needs to create the identifier generator which needs to access the classes for the internals to work.

This is expected behavior since when that happens it is assumed the classes are available - and when using hbm2ddl that is the common case in my opinion.

On the other hand if hbm2java can not run on this then yes, this is definitly a bug.

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