-->
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: null column as part of primary key
PostPosted: Thu Mar 30, 2006 9:47 am 
Newbie

Joined: Thu Mar 30, 2006 9:31 am
Posts: 1
I have a database table that has no primary key defined. I cannot change the schema. But a combination of four columns can uniquely identify each record. The problem is that three of the columns could be null.

Typical records are:
-----------------------------
column1 column2 column3 column4
a001 null null null
a001 b001 null null
a001 b001 c001 null
a001 b001 c001 d001
a001 b001 c001 d002
-----------------------------

How can I treat a null column as part of the primary key? Is it possible to use a UserType to map database null to something not null in a java class to deal with it?

I don't have to deal with foreign keys now for these "primary keys".

Thanks.

Peiyun


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 10:50 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You can't. The SQL standards say that primary key columns must be declared not-null, so hibernate's id tag has been designed with this in mind. You cannot model this table as a standalone entity. You can still refer to it via a collection, where the class is defined as a composite-element, but it can't have its own <class> mapping.


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.