-->
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: Collection Mapping Issue with multiple containing types
PostPosted: Tue Mar 18, 2008 9:27 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
I've got a problem and I'm guessing I'm not the first person to run into it. It's not a terribly complex problem, but I've put together some images and a test application to demonstrate it. This is happening with NHibernate 1.2.1 GA.

The root of the problem seems to be the way the <key> element inside a mapped collection is handled. I have the following object model and NHibernate mapping:

Class Diagram
Mapping Document

The issue is in the way NHibernate handles the Parent column for Charlie objects. This schema was generated by NHibernate:

Table Diagram
Generated SQL


Notice that Charlie table has a foreign key constraint to the Bravo table. This causes problems, as I now can't add Charlie objects to Alpha. Notice that the issue isn't only in how the Schema Export happens, but also the query there where I'm searching for all Charlies that are children of an Alpha, it uses the Parent column on the Charlie table.

Is there something I'm doing wrong? I've got an entity type in my application and almost every other entity in our application contains a collection of that type. I can't seem to figure out how to map that in NHibernate.

Also, here is the Visual Studio 2008 project I used to test this:

Project Zip File

Any help is greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 19, 2008 9:36 am 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
For what it's worth, specifying inverse="true" on the collection gets the creation script to work, not creating the Parent column and foreign key constraint in Charlie. But the query won't use the inherited Parent relationship and still tries to build queries with Charlie.Parent.

Is this a defect and something I should open a ticket on, or am I doing something wrong?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 19, 2008 2:12 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
What happens if you change the one-to-many class from "Charlie" to "Entity"?

That said, I'm thinking that while it poses an interesting question in the abstract, or as a "toy" setup, the pattern you are setting up here will have some pretty nasty inefficiencies in real world use. I'm not seeing the gain in any kind of functionality or abstraction.


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.