-->
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: How to map a unique constraint on a nullable property
PostPosted: Fri Sep 02, 2005 1:11 pm 
Newbie

Joined: Wed Mar 02, 2005 11:05 am
Posts: 5
Good evening to everybody !

Maybe someone of you cam help me. The problem I have should be quite common, but I haven't been able to figure out a smart solution.

I have a class Article with a String property eanCode:

class Article {
//...
String eanCode;
}

eanCode cam be null - if it is not it must be unique. How can I map this in an efficient way with Hibernate.

I already tried to use an extra entity class EANCode and a manyToOne relation from Article to EANCode. This seems to be a bit heavyweight for this simple purpose. Moreover I was not able to make Hibernate delete the EANCode automatically when I set the eanCode property in Article to null. (Even with a back-ptr from EANCode to Article - constrained one-to-one mapping and cascade=all-delete-orphan on the other side)

Did anybody have the same problem and what could be an efficient solution. Thanks in advance for any help...

_________________
MrLongleg
------------------------------------------
Life is too short to drink bad wine ;-)


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.