title: Persisting a OneToMany Entity gives javax.faces.el.EvaluationException: javax.ejb.EJBException
body: <p>When i try the save method, it gives me an error but when i try inserting the data directly to the database manually, it works fine. Please is there something am not adding or seeing in my managedbean class? Please Help to keep the explanation as simple and straight as possible. Thanks</p>
  
  <pre><code>@Entity
  @Table(name = "state")
  @NamedQueries({
          @NamedQuery(name = "State.findAll", query = "SELECT s FROM State s"),
          @NamedQuery(name = "State.findByStateId", query = "SELECT s FROM State s WHERE s.stateId = :stateId"),
          @NamedQuery(name = "State.findByStateName", query = "SELECT s FROM State s WHERE s.stateName = :stateName")})
  public class State implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @NotNull
      @Column(name = "state_id")
      private Integer stateId;
      @Basic(optional = false)
      @NotNull
      @Size(min = 1, max = 45)
      @Column(name = "state_name")
      private String stateName;
      @JoinColumn(name = "country_id", referencedColumnName = "country_id")
      @ManyToOne(optional = false)
      private Country countryId;
  }
  </code></pre>
  
  <p>This the country Entity</p>
  
  <pre><code>@Entity
  @Table(name = "country")
  @NamedQueries({
      @NamedQuery(name = "Country.findAll", query = "SELECT c FROM Country c"),
      @NamedQuery(name = "Country.findByCountryId", query = "SELECT c FROM Country c WHERE c.countryId = :countryId"),
      @NamedQuery(name = "Country.findByCountryName", query = "SELECT c FROM Country c WHERE c.countryName = :countryName")})
  public class Country implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @NotNull
      @Column(name = "country_id")
      private Integer countryId;
      @Basic(optional = false)
      @NotNull
      @Size(min = 1, max = 45)
      @Column(name = "country_name")
      private String countryName;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "countryId")
      private List&lt;State&gt; stateList;
  }
  </code></pre>
  
  <p>ManagedBean</p>
  
  <pre><code>public class stateManagedBean {
      @EJB
      private SessionBean sessionBean;
      @EJB
      private stateSessionBean stateSessionBean;
      private State state = new State();
  
      public stateManagedBean() {
  
      }
      public State getState() {
          return state;
      }
  
      public void setState(State state) {
          this.state = state;
      }
  
      public void save(){
          stateSessionBean.persist(state);
      }        
  }
  </code></pre>
  
  <p>Error Page</p>
  
  <pre><code>javax.faces.el.EvaluationException: javax.ejb.EJBException
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
  
  
  
  Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
      at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.validateOnCallbackEvent(BeanValidationListener.java:90)
      at org.eclipse.persistence.internal.jpa.metadata.listeners.BeanValidationListener.prePersist(BeanValidationListener.java:62)
      at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:698)
  </code></pre>