-->
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: Bug with @Size and 2 level of @OneToMany
PostPosted: Thu Jun 07, 2007 5:22 am 
Newbie

Joined: Tue May 29, 2007 4:46 am
Posts: 6
Hi,
I have an error message when using @Size ... here is the test (using hibernate 3.2.4.ga with entitymanager 3.3.1.GA and validator 3.0.0.GA) :

A boat has a crew of person, a person has one to many shoes.

Code:
@Entity
public class Boat {
   @Id @GeneratedValue
   private Long id;
   
   @OneToMany( cascade=CascadeType.ALL )
   @Size( min = 1 )
   @NotNull
   private List< Person > crew;

   private boolean sink;
   
   public Long getId() {
      return id;
   }

   public boolean isSink() {
      return sink;
   }

   public void setSink(boolean sink) {
      this.sink = sink;
   }

   public List<Person> getCrew() {
      if( crew == null )
         crew = new ArrayList< Person >();
      
      return crew;
   }

   public void setCrew(List<Person> crew) {
      this.crew = crew;
   }
}


Code:
@Entity
public class Person {
   @Id @GeneratedValue
   private Long id;

   @OneToMany( cascade=CascadeType.ALL )
   @Size( min = 1 )
   @NotNull
   private List< Shoe > shoes;

   public List<Shoe> getShoes() {
      if( shoes == null )
         shoes = new ArrayList< Shoe >();
      
      return shoes;
   }

   public void setShoes(List<Shoe> shoes) {
      this.shoes = shoes;
   }

}


Code:
@Entity
public class Shoe {
   @Id @GeneratedValue
   private Long id;

}


Now i'm doing 2 basic transactions :
first creating a boat with a person owning a shoe then I try to sink the boat
Code:
      EntityManagerFactory emf = Persistence.createEntityManagerFactory( "myDatabase" );

// first transaction, persisting entities
      EntityManager em = emf.createEntityManager();      
      em.getTransaction().begin();      
      Boat b = new Boat();
      Person p = new Person();
      Shoe s = new Shoe();
      p.getShoes().add( s );
      b.getCrew().add( p );      
      em.persist( b );
      em.getTransaction().commit();
      em.close();
      
// second transaction trying to sink the boat
      em = emf.createEntityManager();
      em.getTransaction().begin();
      b = em.find( Boat.class, b.getId() );
      b.setSink( true );
      em.getTransaction().commit();
      em.close();
      emf.close();


I get :
Code:
SEVERE: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection [Person.shoes] was not processed by flush()
   at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)


If I remove the @Size constraint then everything work fine.
If I fetch the collection before commiting the second transaction it's fine as well :
Code:
b.getCrew().get( 0 ).getShoes();


Do I miss something ?


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.