[hibernate-issues] [Hibernate-JIRA] Created: (ANN-724) @Size(min) fails in PostLoad

Albert Gorski (JIRA) noreply at atlassian.com
Tue Apr 8 09:24:33 EDT 2008


@Size(min) fails in PostLoad
----------------------------

                 Key: ANN-724
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-724
             Project: Hibernate Annotations
          Issue Type: Bug
          Components: validator
    Affects Versions: 3.3.0.ga
         Environment: hibernate 3.2.6.ga, hibernate-annotations 3.3.1.ga, hibernate-commons-annotations 3.0.0.ga, hibernate-entitymanager 3.3.1.ga, hibernate-validator 3.0.0.ga
Linux (PClinuxOS), MySQL 5.x
            Reporter: Albert Gorski


I've standard parent-child mapping. 
In parent I set validation for the childList list for minimum 1 and maximum 4 (max is not a problem)

I create then a Parent and add Child to childCollection (one child added).
When I call validation
new ClassValidator<Person>(Person.class).getInvalidValues(myPerson);
I see no exception/message - all is fine.

The problem appears when I call entityManager.merge(myPerson) - there is an information that minimum child number is 1.
I think it is a problem in PostLoad -> Parent entity is persisted and validated in PostLoad. Child entries are not yet persisted and it leads to exception.

Is it possible to disable automatic validation in PostLoad or general when I want to validate manually?
Is there any way around? 

Parent-children classes:

@Entity
@Table(name = "parent")
public class Parent {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;

  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy ="parent")
  @Fetch(value = FetchMode.SUBSELECT)
  @OptimisticLock(excluded = true)
  @Size(min = 1, max = 4)
  private List<Child> childList = new java.util.Vector<Child>(4, 1);
}

@Entity
@Table(name = "child")
public class Child extends AbstractEntity {
  /** Serial UID. */
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;

  @ManyToOne(fetch = FetchType.LAZY)
  @NotNull
  private Parent parent;
}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list