-->
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: natural-id error in 3.0?
PostPosted: Thu May 04, 2006 10:15 am 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
<?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.mb.purcell">

<class name="User" table="AuctionUser" lazy="true">

<id name="id" type="int" column="id">
<generator class="native"/>
</id>

<natural-id mutable="true">
<property name="userName"
length="10"/>
</natural-id>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
public class Main
{
private SessionFactory factory;
public static void main(String[] args) throws Exception
{
final Main test = new Main();
Configuration cfg = new Configuration()
.addClass(User.class)
.setProperty(Environment.HBM2DDL_AUTO, "create");
cfg.setProperty("hibernate.show_sql", "true");
test.factory = cfg.buildSessionFactory();
}
}



Full stack trace of any exception that occurs:
run:
[java] 09:11:04,056 INFO Environment:460 - Hibernate 3.0
[java] 09:11:04,071 INFO Environment:478 - loaded properties from resource hibernate.properties: {hibernate.connection.drive
r_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.H
ashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, hibernate.jdbc.use
_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=p
ool1, hibernate.connection.username=root, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:mysql://loca
lhost/demo, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
[java] 09:11:04,071 INFO Environment:505 - using java.io streams to persist binary types
[java] 09:11:04,087 INFO Environment:506 - using CGLIB reflection optimizer
[java] 09:11:04,087 INFO Environment:536 - using JDK 1.4 java.sql.Timestamp handling
[java] 09:11:04,165 INFO Configuration:460 - Mapping resource: com/mb/purcell/User.hbm.xml
[java] 09:11:04,462 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd
in classpath under org/hibernate/
[java] 09:11:04,477 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpat
h
[java] 09:11:04,587 ERROR XMLHelper:59 - Error parsing XML: XML InputStream(15) Element type "natural-id" must be declared.
[java] 09:11:04,602 ERROR XMLHelper:59 - Error parsing XML: XML InputStream(20) The content of element type "class" must matc
h "(meta*,subselect?,cache?,synchronize*,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|co
mponent|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subcl
ass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".
[java] Exception in thread "main" org.hibernate.MappingException: Error reading resource: com/mb/purcell/User.hbm.xml
[java] at org.hibernate.cfg.Configuration.addClass(Configuration.java:467)
[java] at com.mb.purcell.Main.main(Main.java:32)
[java] Caused by: org.hibernate.MappingException: invalid mapping
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:395)
[java] at org.hibernate.cfg.Configuration.addClass(Configuration.java:464)
[java] ... 1 more
[java] Caused by: org.xml.sax.SAXParseException: Element type "natural-id" must be declared.
[java] at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
[java] at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:334)
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:394)
[java] ... 2 more
[java] Java Result: 1
[echo] remember to place your JDBC driver in the lib directory


Name and version of the database you are using:
mysql 5.0

The generated SQL (show_sql=true):
This does not do queries, only creates the table structure.

Debug level Hibernate log excerpt: debug

Within the Hibernate 3.0 install there is an example in the "eg" directory. I am trying to recreate it, because hands on is better than just looking.

Anyway, whenever I try and use the "natural-id" which is used heavily in the "eg" job, it fails. Stating the DTD cannot find the natural-id, see above error message.

When I look at the 3.0 DTD it is there? Any ideas?




Also, the big question, is there any mailing list where people can talk about Hibernate, and ask questions without having to deal with all this point system. There are times when it would be nice, just to throw a question out and see what others are doing, as opposed to having to worry about using all the points up. I think this would really help the community.


Thanks,


Top
 Profile  
 
 Post subject: Resolved Issue Bad Hibernate jar
PostPosted: Thu May 04, 2006 1:48 pm 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
Well as usual, no response to an issue. That is why I love this list so much. You can post questions and never receive any answers......


The problem must of been the jar. The jar I was using "hibernate3.jar" was created "march 31, 2005" and was 1.52MB large. I downloaded it about a month ago from the Hibernate site.

Anyway, I had another jar from a download yesterday which was larger
1.87MB, with a date of Monday, march 20, 2006 and that resolved the issue.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 2:12 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Well atleast few people are manually checking jar files, if there is any change. And it takes some time to analyse and come with a meaningful answer. Who knows which jar file you are using in classpath irrespective of hibernate version?

Quote:
To express anger - it doesnt take a split second - but to say words with anger it takes a lot of time.

To show patience - it needs lots of resilience(calculate, if you can, any quantified equivalent in time) - but doesnt even take one word to show it.


It is good of you to mention about the difference in jar files which helped solve your problem. Changed class files can add to the size - what is important here is changes in DTD.


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.