-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to do something.....
PostPosted: Fri Nov 10, 2006 2:06 pm 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

1.0.1.0

SQL Server 2000

I am trying to find the best way to do something.

I have a contacts table, an address table and a linking table between them called contactaddress. I want the contactaddress to simply inherit the address class so that I only have to deal with one class.

Do I need to subclass this or create joined-subclass, or something else? Also along with not finding good documentation on this I am not finding a decent example either. Can someone point me to a good example of this? I like NHibernate but the documentation seems sketchy....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 8:10 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
You dont inherit contractaddress from anything, in fact you don't define a class for contractaddress at all. It is simply a many-to-many bag if I am reading your question right. Otherwise you'll need to post your mapping files and classes.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 11, 2006 10:42 am 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
OK... Thanks for that. That clears up a lot of confusion I had with bags! :)

Here is my delima now though. Since addresses can belong to many people my contactaddress table has a flag to tell me if the address is the primary address or not for a contact. How would I represent that in this situation?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 11, 2006 8:08 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
That's a little bit trickier. I'm suprised NH does not have better support for this scenario because I have often had association tables with extra columns in them. As far as I know, you can't even use an interceptor to make this work.

You can change your bag to a list, and specify the index column to function as your flag. You can consider the item at index 0 to be the primary item. However, this may require changing your table.

If you cant change your table, I think you have to revert to having 3 entities, included a mapped contactaddress class. You have to map across the 3 using one-to-many and many-to-one and back again. Ugly!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 12, 2006 2:16 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What kind of better support do you have in mind? You don't have to map a full entity for the "middle man" in a many-to-many associations, you can use <composite-element> instead.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 12, 2006 2:54 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
Well, I would like to map a many-to-many relationship using a many-to-many tag. The workaround you are proposing is an indirect one-to-many-many-to-one which is awkward in my opinion. Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 12:53 pm 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
sergey wrote:
What kind of better support do you have in mind? You don't have to map a full entity for the "middle man" in a many-to-many associations, you can use <composite-element> instead.


Well for instance here there are a lot of questions about his out there. Another one that I am finding now, after going down the composite-element path, when to use a bag when to use a set and what exactly is a list? With a list do I always have to use the iesi.collections.listset class or can I use an arraylist there too? To me a bag and a list are the same thing but because no where are these objects defined in the documentation, I know a chapter is devoted to collections but no where are the object purposes defined, I am again wasting my time having to dig through the message boards for an answer....

A good rule of thumb is to provide a couple of fully working examples of something so that users can immediatly view a db or class definitions and determine "this" is what I am trying to do now how was it implemented... The examples I have in code are not very clear becuase the class names are so abstract. As a lead developer I dont want myself or my guys to spend time having to learn a product 100% before we can use it. With the rush to development that companies push for these days that kind of time is simply not available...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 1:08 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
I agree it would be really nice to have a reference section on list/bag/set and their mapping definitions and their corresponding property types.

I know there is a discussion about different collection types but it's pretty high level and not really specific.

Of course, it's open source... if we don't like it we can help out with the documentation ourselves.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 1:13 pm 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
I might help down the road... I have to learn it first! :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 2:54 pm 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
sergey wrote:
What kind of better support do you have in mind? You don't have to map a full entity for the "middle man" in a many-to-many associations, you can use <composite-element> instead.


Actually, composite-element doesn't do what I need it to do. what my database looks like is

contact
Id
Name

AddressContact
ContactId
AddressId
Primary

Address
Street
City
State
Zip

What I want my classes to look like is:
Contact
Id
Name

Address
Contact
Primary
AddressId
Street
City
State
Zip


I want the Contact Address table to go away like it should with a normal many-to-many relationship. But for storage reasons I want the primary flag to be in the linking table...

Using Composite-Element has done nothing for me other than sending me on a goose chase trying to figure out what the heck a ISet is going to return.... Aparently you dont know what NHibernate is going to do becuase if you create a set it changes it to what ever it feels like putting it into.... That has proved to be a nasty issue the last 24 hours becuase I cant create some sort of container without NHibernate choking... So I will go back to the plain old one-to-many and many-to-many relationships until the documentation is better or we decide to purchase a better tool...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 10:57 pm 
Newbie

Joined: Sat Aug 12, 2006 12:58 pm
Posts: 1
I'm trying to do the same thing as Jwergin, and I've just wasted two days trying to find a way to make it work. I don't want to change the DB structure. Can any of the experts tell me if and how to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 11:07 pm 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
I finally got this to work... pretty much like the examples I could find... Problem I had was that in the composite-element table you CAN'T use an auto identity column. You have to assign a guid to it or something... There is nothing in the documentation about this so it is purely an assumption that I was working under but it would not work when I wanted the database to assign it but it worked fine when I did...

At any rate it was a typical problem with projects that are converted over from JAVA they usually are great products but the authors spend almost no time on putting together good user documentation. I guess that's why these types of products build so much loyalty... if you spend the time learning it you dont want to learn anything else...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 2:46 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I actually object to the last statement. NHibernate has quite a bit of documentation.

At any rate, please sumbit a JIRA to clarify the documentation on this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 9:18 am 
Newbie

Joined: Fri Nov 10, 2006 1:57 pm
Posts: 11
guess i am looking in the wrong place for ducumentation...

I only found one blurb about composite-element in the entire set of doc's that I have. I found several references to it but only one blurb about what it's goal in life was. No details - no details about a class that uses them... There was an example implementation of it and that is how I ended up solving it but because of the, I can't call it a bug, problem I had with the identity field I kept looking at it for a few weeks longer than I would have liked...

Like I said maybe I am more used to Microsofts documentation tools because 6 months into this and I am still winging it with NHibernate most of the time.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 11:07 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Go buy Hibernate in Action and learn how to use Google. Documentation is out there, too, called SOURCE CODE.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

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.