Uploaded image for project: 'Hibernate ORM'
  1. HHH-11216

@ElementCollection for enumerations is failing when enabling insert ordering

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      When persisting an entity which contains an element collection referencing an enumeration, an exception occurs when hibernate.order_inserts is set to true. The following examples gives my test setup (also attached as simple maven test project)

      Enumeration

      public enum Category {
      
          A("TEST1"), B("TEST2"), C("TEST3");
      
          private String name;
      
          /**
           * @param name The human readable standard name
           */
          Category(final String name) {
              this.name = name;
          }
      
          /**
           * @return The human readable standard name
           */
          public String getName() {
              return name;
          }
      }
      

      Entity class

      @Entity
      @Table(name = "TASK")
      public class Task {
      
          @Id
          @Column(name = "id")
          private int id;
      
          @ElementCollection(targetClass = Category.class, fetch = FetchType.LAZY)
          @JoinTable(name = "TASK_CATEGORY", joinColumns = { @JoinColumn(name = "TASK_ID") })
          @Enumerated(EnumType.STRING)
          @Column(name = "CATEGORY", nullable = false)
          private final Set<Category> categories = new HashSet<>();
      
          public void addCategory(Category c) {
              categories.add(c);
          }
      
          public Set<Category> getCategories() {
              return categories;
          }
      }
      

      persistence.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                   http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
          version="2.0">
      
          <persistence-unit name="HibernateTestPU">
              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
      
              <class>hibernate.tests.entity.Task</class>
              <exclude-unlisted-classes>true</exclude-unlisted-classes>
      
              <properties>
                  <property name="hibernate.connection.url" value="jdbc:h2:mem:hibernatetest" />
                  <property name="hibernate.connection.driver_class" value="org.h2.Driver" />
                  <property name="hibernate.connection.username" value="SA" />
                  <property name="hibernate.connection.password" value="" />
                  <property name="hibernate.show_sql" value="true" />
                  <property name="hibernate.format_sql" value="true" />
                  <property name="hibernate.hbm2ddl.auto" value="update" />
      
                  <property name="hibernate.order_inserts" value="true" />
              </properties>
          </persistence-unit>
      </persistence>
      

      Stacktrace

      Caused by: org.hibernate.MappingException: collection was not an association: hibernate.tests.entity.Task.categories
      	at org.hibernate.type.CollectionType.getAssociatedEntityName(CollectionType.java:502)
      	at org.hibernate.engine.spi.ActionQueue$InsertActionSorter.addParentChildEntityNames(ActionQueue.java:1149)
      	at org.hibernate.engine.spi.ActionQueue$InsertActionSorter.sort(ActionQueue.java:1091)
      	at org.hibernate.engine.spi.ExecutableList.sort(ExecutableList.java:252)
      	at org.hibernate.engine.spi.ActionQueue.sortActions(ActionQueue.java:760)
      	at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:221)
      	at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:85)
      	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38)
      	at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1406)
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: