-->
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.  [ 1 post ] 
Author Message
 Post subject: Is many-to-one mapping appropriate here?
PostPosted: Fri Apr 09, 2004 1:49 pm 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
Hibernate 2.1.2, Spring 1.0.RC1, MSSQLServer, JDK 1.4.2_01.

If I have a domain class like

public class Vacation{
private int visitNumber;
Collection places; // Place
}


public class Place{
private Country belongsTo;
private String description;
private int daysStayed;
}

The country class is mapped to an "immutable" lookup table.
public class Country{
private String id;
private String name;
}


I have mapped Vacation to have a set of Place objects.
I have mapped Country as a many-to-one class within Place with Cascade='none'. This is because Country table is a lookup table that can never be modified from the Place class.

When I try to persist Vacation object, I get
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Country

I believe I might be using the many-to-one in the wrong context here since my Country object is supposed to be immutable.
____________________________________________________________
Are there any alternatives other than refactoring Place class like
public class Place{
private String countryID;
private String description;
private int daysStayed;
}
and removing the many-to-one mapping in Place to the Country class.
___________________________________________________________

Thanks
Madhu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.