-->
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.  [ 6 posts ] 
Author Message
 Post subject: Invalid Mapping if both <version> and <property>
PostPosted: Wed Jan 19, 2005 10:43 am 
Newbie

Joined: Wed Jan 19, 2005 6:11 am
Posts: 3
Hibernate version: 2.1.7c

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="test">
<class name="TempVersionTest" table="TEMP_VERSION_TEST">

<id
column="id"
name="id"
type="integer"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="NAME"
length="30"
/>
<version column="LOCK_NUM" name="lockNum" type="integer"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

public static void main(String[] args) throws Exception {
String mappingFile = "TempVersionTest.hbm";
Configuration config = new Configuration();
config.addFile(mappingFile);
}

Full stack trace of any exception that occurs:

2005-01-19 19:49:10,279 INFO [net.sf.hibernate.cfg.Environment] Hibernate 2.1.7
2005-01-19 19:49:10,295 INFO [net.sf.hibernate.cfg.Environment] loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.EhCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=dor_tip5, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@pxlqa-db:1521:indqadb, hibernate.connection.password=password, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
2005-01-19 19:49:10,342 INFO [net.sf.hibernate.cfg.Environment] using java.io streams to persist binary types
2005-01-19 19:49:10,342 INFO [net.sf.hibernate.cfg.Environment] using CGLIB reflection optimizer
2005-01-19 19:49:10,342 INFO [net.sf.hibernate.cfg.Environment] using JDK 1.4 java.sql.Timestamp handling
2005-01-19 19:49:10,357 INFO [net.sf.hibernate.cfg.Configuration] Mapping file: TempVersionTest.hbm
2005-01-19 19:49:10,857 DEBUG [net.sf.hibernate.util.DTDEntityResolver] trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
2005-01-19 19:49:10,857 DEBUG [net.sf.hibernate.util.DTDEntityResolver] found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
2005-01-19 19:49:11,076 ERROR [net.sf.hibernate.util.XMLHelper] Error parsing XML: TempVersionTest.hbm(21) The content of element type "class" must match "(meta*,(cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,(subclass*|joined-subclass*))".
2005-01-19 19:49:11,092 ERROR [net.sf.hibernate.cfg.Configuration] Could not configure datastore from file: TempVersionTest.hbm
net.sf.hibernate.MappingException: invalid mapping
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:173)
at com.tpt.thresher.server.schedule.gas.core.helper.TestDTO.main(TestDTO.java:43)
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,(cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,(subclass*|joined-subclass*))".
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1150)
at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1742)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1383)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1260)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
at org.dom4j.io.SAXReader.read(SAXReader.java:323)
at org.dom4j.io.SAXReader.read(SAXReader.java:218)
at org.dom4j.io.SAXReader.read(SAXReader.java:207)
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:172)
... 1 more
net.sf.hibernate.MappingException: net.sf.hibernate.MappingException: invalid mapping
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:179)
at com.tpt.thresher.server.schedule.gas.core.helper.TestDTO.main(TestDTO.java:43)
Caused by: net.sf.hibernate.MappingException: invalid mapping
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:173)
... 1 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,(cache|jcs-cache)?,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|idbag|array|primitive-array)*,(subclass*|joined-subclass*))".
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1150)
at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1742)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1383)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1260)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
at org.dom4j.io.SAXReader.read(SAXReader.java:323)
at org.dom4j.io.SAXReader.read(SAXReader.java:218)
at org.dom4j.io.SAXReader.read(SAXReader.java:207)
at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:172)
... 1 more
Exception in thread "main"


Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true): No session used. Getting a parsing exception

Debug level Hibernate log excerpt: Mentioned above

IDE Used: Eclipse

Hibernate throws a Mapping Exception if both the <version> and the <property> elements exist for the same class mapping.
However, if the <property> element is removed from the mapping, then no exception is thrown.
Why can't a mapping document contain both property and version?

Thanks,

Vishal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 10:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The order is relevant, look at the DTD - version has to be above property.


Top
 Profile  
 
 Post subject: Why cant a mapping have both <version> AND <timesta
PostPosted: Wed Jan 19, 2005 12:16 pm 
Newbie

Joined: Wed Jan 19, 2005 6:11 am
Posts: 3
Thanks for the prompt reply, Michael. And sorry about the stupid post. I should have looked at the DTD.

Another question is, why cant both the version and the timestamp elements both be present for the same class mapping? All our legacy DB tables have the following two columns - lock_num (number) and last_modify_dt (date). We use lock_num for versioning, and the last_modify_dt field to keep track of the last_modified_time. Will I have to manually update the last_modify_dt if I decide to use the version element? Is there any other workaround?

Thanks,

Vishal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Did you try to find a workaround before posting?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you don't use a timestamp for optimistic locking, dont use <timestamp> - update it via a trigger or in an Interceptor


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 1:51 pm 
Newbie

Joined: Wed Jan 19, 2005 6:11 am
Posts: 3
Ok. Then I'll have to use an interceptor (We dont use db triggers as a development practise).

Christian, I was aware of interceptors as a workaround. I wanted to know if there is any other way.

Thank you both for your replies.


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