-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotating object relationships
PostPosted: Wed Jul 30, 2008 10:54 pm 
Newbie

Joined: Sun Jul 27, 2008 4:23 am
Posts: 10
OK, I have the following objects

InsuranceSearchData
Driver
Vehicle
Incident

InsuranceSearchData can have zero or more Drivers (List<Driver>), and zero or more Vehicles (List<Vehicle>).

A Vehicle has a primary driver and a list of zero or more secondary drivers (List<Driver>), but should be able to be saved before the primary driver is set.

A Driver as zero or more incidents (List<Incident>)

For business reasons, the data should be able to be saved to the database as information is entered, which means that a Vehicle will be saved before its drivers are set, a Drier will be saved before its incidents are set, etc.

The schema is auto-generated using hibernatetool

I'd annotated them as follows (leaving out much of the other detail):

Code:
InsuranceSearchData:

@CollectionOfElements
private List<Driver>               driverList;
@CollectionOfElements
private List<Vehicle>             vehicleList;

Driver:

@OneToMany
private List<Incident>              incidentList;

Vehicle:
@ManyToOne
private Driver primaryDriver;
@ManyToMany
private List<Driver> secondaryDriver;


I'm assuming I need some additional annotations to make everything work. Any ideas here?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 4:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

any particular problem you are facing? The provided annotations seems reasonable and could of course be extended, for example with cascading options or further constraints, ...
Is it something particular you are after or do you have a problem to get it to work at all?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 11:41 am 
Newbie

Joined: Sun Jul 27, 2008 4:23 am
Posts: 10
I somehow got double-posted and put a follow-up on the other posting:
http://forum.hibernate.org/viewtopic.php?t=989197 where I have the full error.

I think it might be a question of setting up cascades, although my first attempt (putting an @Cascade annotation on the List<Vehicle> doesn't seem to work. When I get into the office, I can try putting the info there.

-dh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 01, 2008 9:50 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed, I would think that the CascadeType option would do the trick.

Good luck, and thanks for the update!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Here's the solution
PostPosted: Mon Aug 11, 2008 4:56 pm 
Newbie

Joined: Sun Jul 27, 2008 4:23 am
Posts: 10
It turned out to be a conflict between some annotations being imported from javax.persistence and others being imported from org.hibernate.annotations


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