1 Reply Latest reply on Sep 22, 2014 5:11 PM by Karl Nicholas

    Hibernate 4.2 Schema Generation Bug?

    Karl Nicholas Newbie

      Hibernate (Core {4.2.7.SP5-redhat-1}, using dialect PostgreSQL82Dialect) is generating a schema I don't understand, and it is failing when I think it shouldn't. The exception I'm getting is

       

          ERROR: ERROR: null value in column "aggregategroupmap_id" violates not-null constraint
            Detail: Failing row contains (1, 2, BILLPROGRESS, null, null).

       

      Which is true since I didn't attempt to insert anything into the other column. I don't think I should have to because the columns refer to two different Maps.

      This is my main MyClass class.

       

          import java.io.Serializable;
          import java.util.*;

          import javax.persistence.*;

          @SuppressWarnings("serial")
          @Entity public class MyClass implements Serializable {
              @Id @GeneratedValue private Long id;

              @OneToMany(cascade={CascadeType.ALL})
              private Map<String, GroupInfo> aggregateGroupMap;
              @OneToMany(cascade={CascadeType.ALL})
              private Map<String, GroupInfo> computationGroupMap;

              public MyClass() {
                   aggregateGroupMap = new TreeMap<String, GroupInfo>();
                   computationGroupMap = new TreeMap<String, GroupInfo>();
              }

              public Map<String, GroupInfo> getAggregateGroupMap() {
                   return aggregateGroupMap;
              }
              public Map<String, GroupInfo> getComputationGroupMap() {
                   return computationGroupMap;
              }

          }

       

      This is a second class, referenced by the first class.


          import java.io.Serializable;
          import java.util.*;

          import javax.persistence.*;

          @SuppressWarnings("serial")
          @Entity public class GroupInfo implements Serializable {
              @Id @GeneratedValue private Long id;

              @ElementCollection
              @OrderColumn
              private List<String> groupLabels;
              @ElementCollection
              @OrderColumn
              private List<String> groupDescriptions;

              public GroupInfo() {
                  groupLabels = new ArrayList<String>();
                  groupDescriptions = new ArrayList<String>();
              }

              public List<String> getGroupLabels() {
                  return groupLabels;
              }
              public List<String> getGroupDescriptions() {
                  return groupDescriptions;
              }
          }

       

      This class attempts to persist Objects:


          import java.util.*;

          import javax.persistence.*;

          public class TestIt {

              public static void main(String... args) throws Exception {
                  EntityManagerFactory emf = Persistence.createEntityManagerFactory("JpaTest");
                  EntityManager em = emf.createEntityManager();

                  MyClass myClass = new MyClass();
                  GroupInfo groupInfo = new GroupInfo();
                  groupInfo.getGroupLabels().addAll(new ArrayList<String>(Arrays.asList(new String[] {"SKEWNESS"})));
                  myClass.getComputationGroupMap().put("BILLPROGRESS", groupInfo);
       
                  EntityTransaction tx = em.getTransaction();
                  tx.begin();
                  em.persist(myClass);
                  tx.commit();
       
                  em.close();
              }

          }

       

      As far as I can tell, this is the problem table:


         create table MyClass_GroupInfo (

            MyClass_id int8 not null,

            computationGroupMap_id int8 not null,

            computationGroupMap_KEY varchar(255),

            aggregateGroupMap_id int8 not null,

           aggregateGroupMap_KEY varchar(255),

           primary key (MyClass_id, aggregateGroupMap_KEY)

        );

       

      I tried adding @Column(nullable=true) but it didn't make any difference. Any suggestions?