HHH-6068 - Test case
This commit is contained in:
parent
2ac8c0c007
commit
0645acf04f
|
@ -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() );
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
|
||||
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
|
||||
version="2.0">
|
||||
<persistence-unit-metadata>
|
||||
<persistence-unit-defaults>
|
||||
<schema>OTHER_SCHEMA</schema>
|
||||
</persistence-unit-defaults>
|
||||
</persistence-unit-metadata>
|
||||
</entity-mappings>
|
Loading…
Reference in New Issue