aspose file tools*
The moose likes Object Relational Mapping and the fly likes Question on Sets of Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Question on Sets of Objects" Watch "Question on Sets of Objects" New topic
Author

Question on Sets of Objects

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I now have a need to include a set of object in one of my mapping files. I was reading the part on this in HiA and the way they say to define a set is:



So taking this as an example, if I already have a mapping file that defines Image do I still need to include all the properties? Can't you tell hibernate that I already have this mapping defined, just use it?
[/code]


GenRocket - Experts at Building Test Data
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Hi Gregg

i know nothing about composite-ids

that said, here�s how i understand simple parent child relationship:

in class Person you define a cars Set, and also have add/remove aCar methods

in Person.hbm.xml you can define:


in Car.hbm.xml you might have:


in class Car you'll implement a way to navigate to Person, if you want:
Person person = new Person;
and also accessors for person
if I already have a mapping file that defines Image do I still need to include all the properties?

what i did is enough

hope this helps


java amateur
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks. I think you are on the right track for the way I presented the question. However, looking back at it and what I need to do, I need to add some more information. So here is what I am doing.

In my application I have a way of browsing my issues. I can apply a filter to the view. I want to be able to save filters so that they can be loaded instead of having to go through and select all the options every time. So I created a Filter class. There are 2 sets in Filter. I have a Set of technicians (Users) and a set of status (IssueStatus). So one or more of those 2 can be selected.

Here are my table structures

t_filter
---------
filter_id
filter_name
on_from_date
to_date
owner

t_filter_assignment
-------------------
filter_id (fk t_filter.filter_id)
user_id fk (fk t_user.user_id)

t_filter_status
----------------
filter_id (fk t_filter.filter_id)
status_id (fk t_issue_status.status_id)

So the data might look like this:



So then when I pull my Filter object it automagically goes and gets all the assignments and status associated with that filter_id

I hope this made sense. I really don't have a clue as to how to map this.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281

i'm afraid i'm unable to help you in this

in first place you'r doing the opposite way i do: i'm used to first write domain class objects, write respective hbm.xml and then use hibernate to create database, while you start from database.

what imediatly stroke my mind was: why not use hql to filter?
but then filters change... but you could save users choices and build queries from there.. and save them.. but looks quite rudimentary...

speaking strictly about mapping, shouldnt be dificult to map those classes - there's a tool that generates pojos from database schemas, called midlegen, if i remember well
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
What you've defined here is actually two many-to-many relationships. The Users and Statuses are not owned by the Filter, and each can be assigned to multiple Filters (my assumption from your table model). That you don't have any information attached to the association will make this mapping easier.

I haven't done many-to-many associations in Hibernate, but give it a shot and see what you can make of it. I suspect you still use a <set> but replace <composite-element> with <many-to-many>. You only use <c-e> if you need to attach information to the association like dateAdded, etc.

You don't need to specify the properties since you are relating to an existing Hibernate-mapped object.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by David Harkness:
What you've defined here is actually two many-to-many relationships. The Users and Statuses are not owned by the Filter, and each can be assigned to multiple Filters (my assumption from your table model). That you don't have any information attached to the association will make this mapping easier.

I haven't done many-to-many associations in Hibernate, but give it a shot and see what you can make of it. I suspect you still use a <set> but replace <composite-element> with <many-to-many>. You only use <c-e> if you need to attach information to the association like dateAdded, etc.

You don't need to specify the properties since you are relating to an existing Hibernate-mapped object.


Thanks David. I'll give it a shot tomorrow and then update.
 
 
subject: Question on Sets of Objects