-->
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: Not null constrain and InheritanceType.SINGLE_TABLE ?
PostPosted: Mon Sep 03, 2007 12:47 pm 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, i have an abstract base class:

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TaxBase")
abstract public class TaxBaseImp implements RequiresResetOfCalculationData {



Now i want to ensure that a property in a subclass can't be null.
Code:
@Entity
@DiscriminatorValue("Sammelbaustein")
public class TaxBaseSammelbaustein extends TaxBaseImp {


with the attribute
Code:
@OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(nullable = false)
    private UniversalTarifNew tarifImp;


Which cause problems wit another subclass, which doesn't have that property.
Code:
Entity
@DiscriminatorColumn(name = "TaxBalanceSheet")
public class TaxBaseBalanceSheet extends TaxBaseImp implements RequiresResetOfCalculationData {


So my question is, cause
Code:
@JoinColumn(nullable = false)

seems to be to strong, what is the right way to do that?
Code:
@OneToOne(cascade = CascadeType.ALL, optional = false)
is causing the same problems.

Is this possibly? Can I combine a discrimantor-value with a not null constraint?

But anyway, I'll probably give up the constraint or I will change the InheritanceType. I have chosen
SINGLE_TABLE cause this is the only additional attribute in all subclasses at the moment.

May be to change the InheritanceType is the better way in any case, but it would like to know how to do that or at least that it isn't possible.

Thanks a lot.

Greetings Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 8:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Using @NotNull from Hibernate Validator will make sure the property is not null in the VM before flushing the data to the database

_________________
Emmanuel


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.