We're updating the issue view to help you get more done. 

@ElementCollection for enumerations is failing when enabling insert ordering

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 @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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?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

1 2 3 4 5 6 7 8 9 10 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)

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Markus Jessenitschnig

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.4

Priority

Blocker