-->
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.  [ 2 posts ] 
Author Message
 Post subject: Empty id tag in mapping generates a parse error
PostPosted: Mon Oct 29, 2007 1:07 pm 
Newbie

Joined: Mon Oct 29, 2007 12:24 pm
Posts: 10
I am trying to use an empty id tag in a data mapping because I have a composite key and I want to assign both keys manually. I have tried using the composite-id tag but that fails as well, so I will post that issue in a separate thread.

According to the info here:

http://www.hibernate.org/hib_docs/reference/en/html/mapping.html

Quote:
5.1.4. id

Mapped classes must declare the primary key column of the database table.


and

Quote:
If the name attribute is missing, it is assumed that the class has no identifier property.


So I should be able to have an id tag with no name attribute.

Here is the .hbm.xml file.

Code:
<?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>

        <id />
        <property name="unitprice" column="UnitPrice" type="big_decimal" />
   <property name="qty" column="Quantity" type="short" />
   <property name="discount" column="Discount" />
    </class>
</hibernate-mapping>


I am using hibernate through the grails framework. The exception thrown is org.hibernate.InvalidMappingException: Could not parse mapping document.

If I fill in the column info for the id tag, it works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 5:32 pm 
Newbie

Joined: Mon Oct 29, 2007 12:24 pm
Posts: 10
This appears to me to be a bug in the hibernate documentation. I tested this outside of the Grails framework, in a pure hibernate environment, and the bottom line is that you cannot have an empty id tag.

If you do, you will get an exception saying you need to specify a type for the tag. If you specify a type (e.g. type="integer"), then hibernate will expect that your table has a column called id.


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