Beginner |
|
Joined: Tue Nov 29, 2005 4:42 pm Posts: 49 Location: Atlanta, GA
|
I have an object that essentially is like an enumerable type called Namespace. It's simply an ID and a namespace. I want to be able to something like:
Document doc = new Document( new Namespace( 'somenamespace' ) );
Now when I commit the Document object to the database it will create an new entry if and only if the Namespace.namespace property is unique. Otherwise it will just map it to the existing Namespace object saved in the database.
I have mapped the Namespace object like
public class SchemaNamespace {
@Id @GeneratedValue
@Column( name= "NamespaceID" )
private Integer id;
@Column( name = "Namespace", unique = true )
private String namespace;
}
I've set the unique constraint to true thinking that would cause hibernate to select on the table before inserting new Namespace objects. But, if do the code like I've typed above it will create a new namespace object assigning it a different ID.
How do I make hibernate enforce the uniquness of Namespace.namespace so it doesn't insert duplicate entires?
Thanks
Charlie
|
|