-->
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: Problem with one-to-many mapping
PostPosted: Thu Jul 02, 2009 11:19 am 
Newbie

Joined: Thu Jul 02, 2009 10:33 am
Posts: 2
I am having trouble understanding an error I am getting while trying to set up a one-to-many association in Hibernate 3.1.

My database consists of three tables:

Code:
tblGroups:   
id_g  (PK)

tblItems:
id_i  (PK)

tblGroupings:
id  (PK)
id_g  (FK)
id_i  (FK)


This is intended to represent a structure between objects such as: Group--(0..1)--------------------(0..*)--Item

I have used the hibernate_reference.pdf as supplied in the download as guidance, and I thought the scenario as covered ing section 7.5.1 one to many / many to one matched my problem. As a result I have set up my hibernate mapping as follows:

<hibernate-mapping package="spike.grouping">
. <class name="Group" table="tblGroups"
. . ....
. . ....
. . <set name="items" table="tblGroupings">
. . . <key column="id_g" />
. . . <many-to-many column="id_i" unique="true" class="Item"/>
. . </set>
. </class>

. <class name="Item" table="tblItems" dynamic-update="true" optimistic-lock="version">
. . ....
. . <join table="tblGroupings" inverse="true" optional="true">
. . . <key column="id_i"/>
. . . <many-to-one name="Group" column="id_g" not-null="true"/>
. . </join>
. </class>

</hibernate-mapping>


However, when I run my unit tests I get the following error which I do not understand, (I've cut the bulk of it out, just listing line details, I can give the fill stack trace if needed:

Quote:
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:424)
.........
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(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)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
...........
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:421)
... 40 more



Obvisouly it's informing me that I've done somthing wrong in my mapping, but I do not undersand which bit, if any it is telling me is wrong.

Any help would be very much appreciated.


Top
 Profile  
 
 Post subject: Re: Problem with one-to-many mapping
PostPosted: Thu Jul 02, 2009 12:02 pm 
Newbie

Joined: Thu Jul 02, 2009 10:33 am
Posts: 2
Ok, as always the process of writing out the question sheds a little more light.

The problem was that I had other elements in my mapping along the lines of:

<hibernate-mapping package="spike.grouping">

. <class name="Item" table="tblItems" dynamic-update="true" optimistic-lock="version">
. . ....
. . <join table="tblGroupings" inverse="true" optional="true">
. . . <key column="id_i"/>
. . . <many-to-one name="Group" column="id_g" not-null="true"/>
. . </join>

. . <set name="someProperty"...>
. . . .......
. . </set>
. </class>
</hibernate-mapping>

E.g, <set... defines AFTER the join, this does not work and was the cause of my problem.

It was solved by moving the <join .. to the bottom of the class definition. I thought the class mention in the exception trace was refering to the 'class' element of the <many-to-many> tage of the Group mapping.


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.