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,