-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-11216 - @ElementCollection for enumerations is failing when enabl…
…ing insert ordering
- Loading branch information
1 parent
801974f
commit aa5f893
Showing
2 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
hibernate-core/src/test/java/org/hibernate/test/insertordering/ElementCollectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.test.insertordering; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import javax.persistence.CollectionTable; | ||
import javax.persistence.ElementCollection; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.SequenceGenerator; | ||
import javax.persistence.Table; | ||
|
||
import org.hibernate.cfg.Environment; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; | ||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; | ||
import org.junit.Test; | ||
|
||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; | ||
|
||
/** | ||
* @author Andrea Boriero | ||
*/ | ||
@TestForIssue(jiraKey = "HHH-11216") | ||
public class ElementCollectionTest extends BaseNonConfigCoreFunctionalTestCase { | ||
|
||
@Override | ||
protected Class[] getAnnotatedClasses() { | ||
return new Class[] {Task.class}; | ||
} | ||
|
||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); | ||
|
||
@Override | ||
protected void addSettings(Map settings) { | ||
settings.put( Environment.ORDER_INSERTS, "true" ); | ||
settings.put( Environment.STATEMENT_BATCH_SIZE, "10" ); | ||
settings.put( | ||
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, | ||
connectionProvider | ||
); | ||
} | ||
|
||
@Test | ||
public void testBatchOrdering() { | ||
doInHibernate( this::sessionFactory, session -> { | ||
Task task = new Task(); | ||
task.addCategory(Category.A); | ||
session.persist( task ); | ||
|
||
Task task1 = new Task(); | ||
task1.addCategory(Category.A); | ||
session.persist( task1 ); | ||
} ); | ||
} | ||
|
||
@Override | ||
public void releaseResources() { | ||
super.releaseResources(); | ||
connectionProvider.stop(); | ||
} | ||
|
||
@Entity | ||
@Table(name = "TASK") | ||
public static class Task { | ||
|
||
@Id | ||
@SequenceGenerator(name = "ID", sequenceName = "TASK_SEQ") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID") | ||
private int id; | ||
|
||
@ElementCollection(targetClass = Category.class) | ||
@CollectionTable(name = "TASK_CATEGORY", joinColumns = {@JoinColumn(name = "TASK_ID")}) | ||
@Enumerated(EnumType.STRING) | ||
private final Set<Category> categories = new HashSet<>(); | ||
|
||
public void addCategory(Category c) { | ||
categories.add( c ); | ||
} | ||
} | ||
|
||
public enum Category { | ||
|
||
A( "CAT1" ), B( "CAT2" ); | ||
|
||
private String name; | ||
|
||
Category(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
} |