-->
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.  [ 5 posts ] 
Author Message
 Post subject: NotNull propagated to sibling classes in hierarchy !!!
PostPosted: Sun Sep 13, 2009 9:00 am 
Newbie

Joined: Sat Jan 03, 2009 6:33 pm
Posts: 11
Hi,
Following the advice of hardy.ferentschik, I post my question in this forum (original is at https://forum.hibernate.org/viewtopic.php?f=9&t=999591&start=0)

Quote:
I'm using validator-3.1, core-3.3.1, annotations-3.4.
Here is my problem, may be a bug:

Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Parent
{
    @Id
    int id;

    @Column(nullable = true)
    String string;

    public int getId() { return this.id; }
    public String getString() { return this.string; }
}

@Entity
public class CanBeNull
    extends Parent
{
}

@Entity
public class CannotBeNull
    extends Parent
{
    // omitted for demo: @Column(nullable = false)
    @NotNull
    @Override
    public String getString() { return this.string; }
}



Now the DDL looks like:

Code:
CREATE TABLE cannot_be_nulls
(
  id integer NOT NULL,
  string character varying(255) NOT NULL,
  CONSTRAINT cannot_be_nulls_pkey PRIMARY KEY (id)
)
CREATE TABLE can_be_nulls
(
  id integer NOT NULL,
  string character varying(255) *************NOT NULL*******************,
  CONSTRAINT can_be_nulls_pkey PRIMARY KEY (id)
)



This does not happen if I use @MappedSuperclass on Parent, but I need @Entity because some other entity have references to Parent.
This is quite annoying... Is there something i can do, is this a bug (looks like), should i open an issue on jira ?


Answer:
Quote:
seems to be a bug. The DDL is also correct when @MappedSuperclass is used or when CannotBeNull is not mapped at all.
However, I think this is really a Hibernate Tools bug. Hibernate Annotations and Validator provide the meta data, but Hibernate
Tools generates the actual DDL. You might want to post your question there or check Jira for Hibernate Tools.


Should I fill a Jira?
Thanks

David


Top
 Profile  
 
 Post subject: Re: NotNull propagated to sibling classes in hierarchy !!!
PostPosted: Wed Sep 16, 2009 5:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - I think to remember this being a bug...but the testsuite should have the same problem.

Open a bug in Hibernate Annotations or Core.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: NotNull propagated to sibling classes in hierarchy !!!
PostPosted: Thu Sep 24, 2009 3:38 pm 
Newbie

Joined: Sat Jan 03, 2009 6:33 pm
Posts: 11
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4461


Top
 Profile  
 
 Post subject: Re: NotNull propagated to sibling classes in hierarchy !!!
PostPosted: Thu Dec 03, 2009 5:14 pm 
Newbie

Joined: Sat Jan 03, 2009 6:33 pm
Posts: 11
Hi,

I come back on this issue since there is still no target version for any fix in JIRA...
The DDL error can be worked around but how am I supposed to do with the nullability check ?
Code:
javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: xxxx.Member.firstName
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226)
   at xxxx.jpa.test.AbstractModelDatabaseTest.persistAndFlush(AbstractModelDatabaseTest.java:422)
   at xxxx.MemberDatabaseTest.create2(MemberDatabaseTest.java:63)
   at org.unitils.UnitilsTestNG.run(UnitilsTestNG.java:103)
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: xxxx.Member.firstName
   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)
   at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
   at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
   ... 31 more
... Removed 28 stack frames


I really must do something wrong since I cannot believe that this simple use case has not been reported (and fixed) for years ???
Any advice ?

Thanks


Top
 Profile  
 
 Post subject: Re: NotNull propagated to sibling classes in hierarchy !!!
PostPosted: Fri Dec 04, 2009 1:00 pm 
Newbie

Joined: Sat Jan 03, 2009 6:33 pm
Posts: 11
The only workaround i found if anyone is interested:

Code:
public class NotNullValidatorWorkaround
    implements Validator<NotNullWorkaround>, Serializable //***** ,PropertyConstraint (does not implement) *****


Code:
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.FIELD })
@ValidatorClass(NotNullValidatorWorkaround.class)
public @interface NotNullWorkaround
{
    String message() default "{validator.notNull}";
}


The DDL must be maintained separately but it's good practive anyway.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.