diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java new file mode 100644 index 0000000000..014f9b9b2f --- /dev/null +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java @@ -0,0 +1,64 @@ +package org.hibernate.test.annotations.id.sequences; + +import org.junit.Assert; +import org.junit.Test; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.id.IdentifierGenerator; +import org.hibernate.id.enhanced.SequenceStyleGenerator; +import org.hibernate.mapping.Table; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.test.annotations.id.sequences.entities.HibernateSequenceEntity; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@TestForIssue(jiraKey = "HHH-6068") +public class HibernateSequenceTest extends BaseCoreFunctionalTestCase { + private static final String SCHEMA_NAME = "OTHER_SCHEMA"; + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + HibernateSequenceEntity.class + }; + } + + @Override + protected void configure(Configuration cfg) { + super.configure( cfg ); + cfg.addResource( "org/hibernate/test/annotations/id/sequences/orm.xml" ); + cfg.setProperty( + Environment.URL, cfg.getProperty( Environment.URL ) + ";INIT=CREATE SCHEMA IF NOT EXISTS " + SCHEMA_NAME + ); + } + + @Test + public void testHibernateSequenceSchema() { + EntityPersister persister = sessionFactory().getEntityPersister( HibernateSequenceEntity.class.getName() ); + IdentifierGenerator generator = persister.getIdentifierGenerator(); + Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); + SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; + Assert.assertEquals( + Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ), + seqGenerator.getDatabaseStructure().getName() + ); + } + + @Test + public void testHibernateSequenceNextVal() { + Session session = openSession(); + Transaction txn = session.beginTransaction(); + HibernateSequenceEntity entity = new HibernateSequenceEntity(); + entity.setText( "sample text" ); + session.save( entity ); + txn.commit(); + session.close(); + Assert.assertNotNull( entity.getId() ); + } +} diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/id/sequences/entities/HibernateSequenceEntity.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/id/sequences/entities/HibernateSequenceEntity.java new file mode 100644 index 0000000000..6d2b840594 --- /dev/null +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/id/sequences/entities/HibernateSequenceEntity.java @@ -0,0 +1,34 @@ +package org.hibernate.test.annotations.id.sequences.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@Entity +public class HibernateSequenceEntity { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private Long id; + + private String text; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} diff --git a/hibernate-core/src/matrix/resources/org/hibernate/test/annotations/id/sequences/orm.xml b/hibernate-core/src/matrix/resources/org/hibernate/test/annotations/id/sequences/orm.xml new file mode 100644 index 0000000000..86d9dfcb9b --- /dev/null +++ b/hibernate-core/src/matrix/resources/org/hibernate/test/annotations/id/sequences/orm.xml @@ -0,0 +1,12 @@ + + + + + OTHER_SCHEMA + + + \ No newline at end of file