-->
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.  [ 12 posts ] 
Author Message
 Post subject: Hibernate Console: InvalidMappingException
PostPosted: Wed Dec 13, 2006 12:12 pm 
Newbie

Joined: Sat Jun 03, 2006 10:40 am
Posts: 4
Greetings:

I have been working this problem for several days now and am confused and believe I am either missing something or we have a problem. I have read the other postings complaining of the “Error while fetching children” problems and believe I am conforming with the responses from max. The Hello project described below works with no problems exactly as described below when executed within the Eclipse IDE. I want to be able to use the Hibernate Console to teach HQL and perform demonstration queries. The configuration data is shown below. No other plugins are installed other than what is currently coming with Eclipse 3.2.1 and Hibernate Tools.

I have two problems:

Problem 1: How can the Hibernate Console not be finding the hbm.xml mapping file with the configurations shown below. According to max, if the classpath is pointing to the directory where the classes are stored, the console should find it. What am I missing here?

Problem 2: Even after I find a configuration that finds the hbm.xml mapping file, it is complaining that it can’t parse it. How can it not parse it when the project runs fine as described above?

Thank you for your attention.

Doktat

*************************************
RELEVANT INFORMATION
*************************************


Eclipse SDK

Version: 3.2.1
Build id: M20060921-0945

Hibernate Console 3.2.0beta8

JAVA: Z:\Java\jdk1.5.0_06\jre\bin\javaw.exe

*************************************
DIRECTORY STUCTURE
*************************************

Hello
/src
HelloMain.java
Message.java
QueryMessage.java
Message.hbm.xml
/bin
/src
HelloMain.class
Message.class
QueryMessage.class
Message.hbm.xml
.classpath
.project
HelloLog.txt
hibernate.cfg.xml
log4j.properties

************************************
hibernate.cfg.xml
************************************
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:oracle:thin:@hostname:1521:SID</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.username">userid</property>
<property name="connection.password">password</property>
<!-- Mapping files -->
<mapping resource="src/Message.hbm.xml"/>
</session-factory>
</hibernate-configuration>
************************************
Message.hbm.xml
************************************
<?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>
<class name="src.Message" table="MESSAGE">
<id
name="id"
column="MESSAGE_ID">
<generator class="increment"/>
</id>
<property
name="text"
column="MESSAGE_TEXT"/>
<many-to-one
name="nextMessage"
cascade="all"
column="NEXT_MESSAGE_ID"/>
</class>
</hibernate-mapping>

************************************
Hibernate Console Configuration
************************************

Name: hello
Configuration file: \Hello\hibernate.cfg.xml

When Classpath is set to: /Hello/bin/src or /Hello/src I get a Lazy Tree Error dialog box with the message: “Error while fetching children Reason: org.hibernate.MappingNotFoundException Reason: src/Message.hbm.xml not found”

When Classpath is set to: /Hello, I get a Lazy Tree Error dialog box with the message: “Error while fetching children Reason: org.hibernate.InvalidMappingException: Could not parse mapping document from resource src/Message.hbm.xml”


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 4:43 pm 
Newbie

Joined: Sat Jun 03, 2006 10:40 am
Posts: 4
I made some progress with the problems I registered above. I realized there was one classpath that I hadn't tried and that was /Hello/bin. When I reset the classpath I needed only to configure the path to the drivers and I was able to access and query. One problem still remains for me. Why does it made a difference whether it reads the hbm.xml mapping file in /Hello/src/Message.hbm.xml or /Hello/bin/src/Message.hbm.xml? ... they are both the same file - but the former yields a faulty error about parsing the mapping file while the later works successfully.

Thank you for contributions.

Doktat


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 5:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you don't show the stacktrace, but my guess is that the stacktrace shows that it cannot complete the parsing because a class cannot be found.

And why can it not be found ? well, because you pointed to the source directory, but not to the class directory.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Hibernate Console: InvalidMappingException
PostPosted: Wed Mar 28, 2007 3:39 pm 
Newbie

Joined: Tue Oct 10, 2006 10:58 am
Posts: 2
I am having the same exception. I get this exception when running hbm2java from ant. Partial stack trace is below. If the class does not exist yet (because I'm trying to auto-generate it from the mapping file),
why would hbm2java even try to load the class whose source file
it is supposed to be generating?

Thanks,

Chris Wolf
===============================================
[...]
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.ja
va:94)
at org.hibernate.tool.ant.Hbm2JavaExporterTask.configureExporter(Hbm2Jav
aExporterTask.java:34)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.ja
va:171)
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)
[...]
Caused by: org.hibernate.MappingException: class com.ms.cis.osadmin.beans.SecRul
es not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper
.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.
java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2164)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2141
)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2118
)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2031
)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBi
nder.java:359)
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:424)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:465
)
--- Nested Exception ---
org.hibernate.InvalidMappingException: Could not parse mapping document from fil
e C:\dev\cis\osadmin\1.0.0\src\packages\com\ms\cis\osadmin\beans\SecRules.hbm.xm
l
at org.hibernate.cfg.Configuration.addFile(Configuration.java:306)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.ja
va:140)
at org.hibernate.tool.ant.ConfigurationTask.addMappings(ConfigurationTas
k.java:123)
[...]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 3:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
did you rememer to set the type for the property ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Hibernate Console: InvalidMappingException
PostPosted: Wed Mar 28, 2007 5:06 pm 
Newbie

Joined: Tue Oct 10, 2006 10:58 am
Posts: 2
I did in one of the property declarations, but I also had a natural-id
declaration without the type attribute. So after adding that type attr, it worked! Thanks.

I would have expected an error message saying a
required attribute is missing, or if it is optional, then
an advisory message stating that getting the property
from that attribute is being skipped and falling back to
an alternate strategy.


[hibernatetool] Failed in building configuration when adding C:\dev\cis\osadmin\
1.0.0\src\packages\com\ms\cis\osadmin\beans\SecRules.hbm.xml
[hibernatetool] org.hibernate.InvalidMappingException: Could not parse mapping d
ocument from file C:\dev\cis\osadmin\1.0.0\src\packages\com\ms\cis\osadmin\beans
\SecRules.hbm.xml
[hibernatetool] org.hibernate.MappingException: class com.ms.cis.osadmin.beans.S
ecRules not found while looking for property: id
[hibernatetool] java.lang.ClassNotFoundException: com.ms.cis.osadmin.beans.SecRu
les
[hibernatetool] A class were not found in the classpath of the Ant task.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 2:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You are welcome to supply a patch ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Hibernate Console: InvalidMappingException
PostPosted: Mon Nov 26, 2007 4:23 am 
Newbie

Joined: Tue Nov 13, 2007 7:08 pm
Posts: 10
Location: Australia
Hibernate Version: 3.2
user127 wrote:
I would have expected an error message saying a
required attribute is missing...


I would have expected that it finds the type via reflection! I have encountered the same problem (following) and so have taken a closer look.

Code:
org.hibernate.MappingException: class fully.qualified.ClassName not found while looking for property: ...
   at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
   at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
   ...
Caused by: java.lang.ClassNotFoundException: fully.qualified.ClassName
   ...


I am looking at the code where the exception originates on line 100 of org.hibernate.util.ReflectHelper (as follows).

Code:
91:   public static Class classForName(String name) throws ClassNotFoundException {
   ...
100:      return Class.forName( name );
101:   }


Note, SimpleValue.setTypeUsingReflection is in the stack trace, which seems reasonable. I don't see why it can't find the class; I don't want to have specify a type for each property. I thought the whole point was that type was optional and reflection would be used. :(

Is there something wrong with my class path? What class loader is being used? What class loader should be used?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 7:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ? How do you expect the *code generator* that generate the beans being able to load the classes that it is about to actually generate ?

if you use hbm2java the types for the properties has to be specified...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 7:28 am 
Newbie

Joined: Tue Nov 13, 2007 7:08 pm
Posts: 10
Location: Australia
max wrote:
huh ? How do you expect the *code generator* that generate the beans being able to load the classes that it is about to actually generate ?


Ahh, I see. My situation is that I have the code already, so I created the mapping and now I want to generate the schema using SchemaExport. Sorry 'bout the confusion.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 7:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok - so you need to put the classes on to the classpath ...just like you would do when compiling code with javac :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: spelling mistake
PostPosted: Mon Nov 26, 2007 9:59 am 
Newbie

Joined: Tue Nov 13, 2007 7:08 pm
Posts: 10
Location: Australia
Oh wow... I had a spelling mistake! Sorry, thanks for your quick reply anyway!

My spelling mistake was actually in the java code... Eclipse kindly asked me if I want to misspell the class name consistently in the code but not the mapping, and I said yes... oops. (I haven't made a mistake like that for a long time, well overdue)

Cheers,
Corin.


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