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: Error reading resource: htest/Test1.hbm.xml
PostPosted: Fri Dec 09, 2005 12:38 pm 
Newbie

Joined: Fri Dec 09, 2005 12:30 pm
Posts: 6
I get the following error. Can anybody help?

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Error reading resource: htest/Test1.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
at htest.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
at htest.Hibernatetest.insertRecord(Hibernatetest.java:27)
at htest.Hibernatetest.main(Hibernatetest.java:16)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:399)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
... 8 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398)
... 9 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 1:27 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
The exception is saying that the tags in your <class> tag don't match the DTD:

(meta*,subselect?,cache?,synchronize*,comment?,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)

Remember that order is important! That's usually what I've done wrong when I get this error.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 1:39 pm 
Newbie

Joined: Fri Dec 09, 2005 12:30 pm
Posts: 6
nathanmoon wrote:
The exception is saying that the tags in your <class> tag don't match the DTD:

(meta*,subselect?,cache?,synchronize*,comment?,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)

Remember that order is important! That's usually what I've done wrong when I get this error.



I am not clear. Order of what? this is the first time hibernate example so I am not very savy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 2:51 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
in htest/Test1.hbm.xml you have:

Code:
<class ...>
(here you have nested elements like <id> <property>, etc.)
</class>


The nested elements have to match the DTD, which specifies what tags can be nested inside your class, and in what order they can appear. This has nothing to do with Hibernate, it's a straight XML problem.

Read up on XML/DTDs if you still can't figure it out, or post your file and someone can tell you what to change. Good luck.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 3:00 pm 
Newbie

Joined: Fri Dec 09, 2005 12:30 pm
Posts: 6
Thanks Nathan!

Everything is generated by MyEclipse I didn't do anything manually. So, I assumed there shouldn't be any problem.

I deleted and tried to do everything new to see if it works.
The Test1.hbm.xml is in Hibernate/src directory, in tst package. Where Test1.java file also exists.

<hibernate-mapping package="tst">

<class name="Test1" table="test1">

<property name="name" column="name" type="string" />
<property name="city" column="city" type="string" />
</class>

</hibernate-mapping>

My hibernate.hbm.xml looks like this :

<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">MySql</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">ravi</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property><mapping resource="tst/Test1.hbm.xml" />


</session-factory>

</hibernate-configuration>

My HibernateSessionFactory.java references :

private static String CONFIG_FILE_LOCATION = "/tst/hibernate.cfg.xml";


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 3:16 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
hairavi wrote:
Everything is generated by MyEclipse I didn't do anything manually. So, I assumed there shouldn't be any problem.


I've never used MyEclipse, but your Test1 class must have either an <id> or <composite-id> tag (for the table primary key), so it's not getting generated correctly.

_________________
nathan


Top
 Profile  
 
 Post subject: could not instantiate id generator
PostPosted: Fri Dec 09, 2005 3:59 pm 
Newbie

Joined: Fri Dec 09, 2005 12:30 pm
Posts: 6
Thanks Nathan.
That was helpful and I was promoted to a new error :

My table structure is :

mysql> CREATE TABLE paper(ID int(3) NOT NULL AUTO_INCREMENT Primary Key, color V
ARCHAR(10) NULL, size VARCHAR(10) NULL);

Log file :

############# create record
Before getting session
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%

org.hibernate.MappingException: could not instantiate id generator
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:92)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:151)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:178)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at tst.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:49)
at tst.htest.insertRecord(htest.java:25)
at tst.htest.main(htest.java:14)
Caused by: org.hibernate.MappingException: Dialect does not support sequences
at org.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:430)
at org.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:65)
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:88)
... 6 more
java.lang.NullPointerException
at tst.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:56)
at tst.htest.insertRecord(htest.java:25)
at tst.htest.main(htest.java:14)
Exception in thread "main"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:02 pm 
Newbie

Joined: Fri Dec 09, 2005 12:30 pm
Posts: 6
My new paper.hbm.xml looks like below :

<hibernate-mapping package="tst">

<class name="Paper" table="paper">
<id name="id" column="ID" type="integer">
<generator class="sequence"/>
</id>

<property name="color" column="color" type="string" />
<property name="size" column="size" type="string" />
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:07 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
you could try

Code:
<generator class="native"/>


(let hibernate decide what generator to use)

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:23 pm 
Newbie

Joined: Fri Dec 09, 2005 12:30 pm
Posts: 6
Thanks Nathan!

I fixed it before seeing your reply. But you get the credit for posting response ;=)

--Ravi


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.