-->
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: Mapping collections with surrogate keys
PostPosted: Tue Apr 29, 2008 1:42 pm 
Newbie

Joined: Thu Jan 17, 2008 1:12 pm
Posts: 8
I was tryin to map a collection of Car objects using a list. I could map them to the table however i could not generate a surrogate key.

@Entity
@Table(name= "garage")
public class Garage {

@Id @GeneratedValue
@Column(name = "garage_id")
private long id;
@org.hibernate.annotations.CollectionOfElements(
targetElement = Car.class)
@JoinTable(
name = "car",

joinColumns = @JoinColumn(name= "garage_id"))

@Column(name ="carname")
private List<Car> auto = new ArrayList<Car>();

*********************************************
@Embeddable
@Table(name ="car")
public class Car {

/*@Id @GeneratedValue
@Column(name = "car_id")
private long id;*/

@Column(name ="name" )
private String name;
@Column (name ="sex")
private String sex;
@org.hibernate.annotations.Parent
private Garage garage;


can anyone help me on how to map the list so that it generate a surrogate primaey key on the collection side table. right now it has a foreign key referencing with garage_id.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 8:56 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
AFAIK the only way to get this is to do an actual entity association rather that a collection of elements. Even Hibernate core (without annotations) requires all the elements to have non-null fields because it uses compound keys.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.