mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 08:35:13 +00:00
Re-enabled additional tests
This commit is contained in:
parent
6f60cd8918
commit
bb7b524e40
@ -4,7 +4,7 @@
|
||||
* 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.nationalized;
|
||||
package org.hibernate.orm.test.nationalized;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
@ -24,7 +24,7 @@
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.orm.test.nationalized;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-10364")
|
||||
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsNationalizedData.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = NationalizedLobFieldTest.MyEntity.class
|
||||
)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(
|
||||
settings = @Setting(name = AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, value = "false")
|
||||
)
|
||||
public class NationalizedLobFieldTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity e = new MyEntity( 1L );
|
||||
e.setState( "UK" );
|
||||
session.save( e );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from MyEntity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNationalization(SessionFactoryScope scope) {
|
||||
scope.inSession(
|
||||
session -> {
|
||||
MyEntity myEntity = session.get( MyEntity.class, 1L );
|
||||
assertNotNull( myEntity );
|
||||
assertThat( myEntity.getState(), is( "UK" ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name = "MyEntity")
|
||||
@Table(name = "my_entity")
|
||||
public static class MyEntity {
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Lob
|
||||
@Nationalized
|
||||
private String state;
|
||||
|
||||
public MyEntity() {
|
||||
}
|
||||
|
||||
public MyEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
* 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.nationalized;
|
||||
package org.hibernate.orm.test.nationalized;
|
||||
|
||||
import java.sql.NClob;
|
||||
import javax.persistence.Entity;
|
||||
@ -17,8 +17,8 @@
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.NationalizationSupport;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.type.CharacterArrayType;
|
||||
@ -30,20 +30,26 @@
|
||||
import org.hibernate.type.NTextType;
|
||||
import org.hibernate.type.StringNVarcharType;
|
||||
import org.hibernate.type.StringType;
|
||||
import org.hibernate.type.descriptor.java.CharacterArrayTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.NVarcharTypeDescriptor;
|
||||
import org.hibernate.type.internal.StandardBasicTypeImpl;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleNationalizedTest extends BaseUnitTestCase {
|
||||
@BaseUnitTest
|
||||
public class SimpleNationalizedTest {
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration", "SpellCheckingInspection"})
|
||||
@Entity( name="NationalizedEntity")
|
||||
@SuppressWarnings({ "UnusedDeclaration", "SpellCheckingInspection" })
|
||||
@Entity(name = "NationalizedEntity")
|
||||
public static class NationalizedEntity {
|
||||
@Id
|
||||
private Integer id;
|
||||
@ -61,10 +67,10 @@ public static class NationalizedEntity {
|
||||
|
||||
@Nationalized
|
||||
private Character ncharacterAtt;
|
||||
|
||||
|
||||
@Nationalized
|
||||
private Character[] ncharArrAtt;
|
||||
|
||||
|
||||
@Type(type = "ntext")
|
||||
private String nlongvarcharcharAtt;
|
||||
}
|
||||
@ -82,20 +88,21 @@ public void simpleNationalizedTest() {
|
||||
assertNotNull( pc );
|
||||
|
||||
Property prop = pc.getProperty( "nvarcharAtt" );
|
||||
if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect ||
|
||||
metadata.getDatabase().getDialect() instanceof CockroachDialect ){
|
||||
final Dialect dialect = metadata.getDatabase().getDialect();
|
||||
if ( dialect.getNationalizationSupport() != NationalizationSupport.EXPLICIT ) {
|
||||
// See issue HHH-10693
|
||||
assertSame( StringType.INSTANCE, prop.getType() );
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
assertSame( StringNVarcharType.INSTANCE, prop.getType() );
|
||||
}
|
||||
|
||||
prop = pc.getProperty( "materializedNclobAtt" );
|
||||
if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect ||
|
||||
metadata.getDatabase().getDialect() instanceof CockroachDialect ){
|
||||
if ( dialect.getNationalizationSupport() != NationalizationSupport.EXPLICIT ) {
|
||||
// See issue HHH-10693
|
||||
assertSame( MaterializedClobType.INSTANCE, prop.getType() );
|
||||
}else {
|
||||
}
|
||||
else {
|
||||
assertSame( MaterializedNClobType.INSTANCE, prop.getType() );
|
||||
}
|
||||
prop = pc.getProperty( "nclobAtt" );
|
||||
@ -105,17 +112,18 @@ public void simpleNationalizedTest() {
|
||||
assertSame( NTextType.INSTANCE, prop.getType() );
|
||||
|
||||
prop = pc.getProperty( "ncharArrAtt" );
|
||||
if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect ||
|
||||
metadata.getDatabase().getDialect() instanceof CockroachDialect ){
|
||||
if ( dialect.getNationalizationSupport() != NationalizationSupport.EXPLICIT ) {
|
||||
// See issue HHH-10693
|
||||
assertSame( CharacterArrayType.INSTANCE, prop.getType() );
|
||||
}else {
|
||||
assertSame( StringNVarcharType.INSTANCE, prop.getType() );
|
||||
}
|
||||
|
||||
else {
|
||||
assertThat( prop.getType(), instanceOf( StandardBasicTypeImpl.class ) );
|
||||
StandardBasicTypeImpl type = (StandardBasicTypeImpl) prop.getType();
|
||||
assertThat( type.getJavaTypeDescriptor(), instanceOf( CharacterArrayTypeDescriptor.class ) );
|
||||
assertThat( type.getJdbcTypeDescriptor(), instanceOf( NVarcharTypeDescriptor.class ) );
|
||||
}
|
||||
prop = pc.getProperty( "ncharacterAtt" );
|
||||
if ( metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect ||
|
||||
metadata.getDatabase().getDialect() instanceof CockroachDialect ) {
|
||||
if ( dialect.getNationalizationSupport() != NationalizationSupport.EXPLICIT ) {
|
||||
// See issue HHH-10693
|
||||
assertSame( CharacterType.INSTANCE, prop.getType() );
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.orm.test.nationalized;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialects;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "10495")
|
||||
@RequiresDialects(
|
||||
value = {
|
||||
@RequiresDialect(value = OracleDialect.class, version = 1000),
|
||||
@RequiresDialect(value = PostgreSQLDialect.class, version = 810)
|
||||
})
|
||||
@DomainModel(
|
||||
annotatedClasses = StringNationalizedTest.NationalizedEntity.class
|
||||
)
|
||||
@SessionFactory
|
||||
public class StringNationalizedTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from NationalizedEntity" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveEntityWithNationalizedProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
NationalizedEntity ne = new NationalizedEntity();
|
||||
ne.name = "Hello";
|
||||
session.save( ne );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inSession(
|
||||
session -> {
|
||||
final Query query = session.createQuery( "from NationalizedEntity where name = :name" );
|
||||
query.setParameter( "name", "Hello" );
|
||||
final List list = query.list();
|
||||
assertThat( list.size(), is( 1 ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name = "NationalizedEntity")
|
||||
@Table(name = "NATIONALIZED_ENTITY")
|
||||
public static class NationalizedEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
@Nationalized
|
||||
String name;
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
* 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.nationalized;
|
||||
package org.hibernate.orm.test.nationalized;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@ -16,8 +16,8 @@
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.NationalizationSupport;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.type.CharacterNCharType;
|
||||
@ -39,7 +39,7 @@
|
||||
*/
|
||||
public class UseNationalizedCharDataSettingTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-10528" )
|
||||
@TestForIssue(jiraKey = "HHH-10528")
|
||||
public void testSetting() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, true )
|
||||
@ -52,11 +52,12 @@ public void testSetting() {
|
||||
final Metadata metadata = ms.buildMetadata();
|
||||
final PersistentClass pc = metadata.getEntityBinding( NationalizedBySettingEntity.class.getName() );
|
||||
final Property nameAttribute = pc.getProperty( "name" );
|
||||
if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect ||
|
||||
metadata.getDatabase().getDialect() instanceof CockroachDialect ){
|
||||
final Dialect dialect = metadata.getDatabase().getDialect();
|
||||
if ( dialect.getNationalizationSupport() != NationalizationSupport.EXPLICIT ) {
|
||||
// See issue HHH-10693
|
||||
assertSame( StringType.INSTANCE, nameAttribute.getType() );
|
||||
}else {
|
||||
}
|
||||
else {
|
||||
assertSame( StringNVarcharType.INSTANCE, nameAttribute.getType() );
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ public void testSetting() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-11205" )
|
||||
@TestForIssue(jiraKey = "HHH-11205")
|
||||
public void testSettingOnCharType() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, true )
|
||||
@ -80,10 +81,11 @@ public void testSettingOnCharType() {
|
||||
final Metadata metadata = ms.buildMetadata();
|
||||
final PersistentClass pc = metadata.getEntityBinding( NationalizedBySettingEntity.class.getName() );
|
||||
final Property nameAttribute = pc.getProperty( "flag" );
|
||||
if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect ||
|
||||
metadata.getDatabase().getDialect() instanceof CockroachDialect ){
|
||||
final Dialect dialect = metadata.getDatabase().getDialect();
|
||||
if ( dialect.getNationalizationSupport() != NationalizationSupport.EXPLICIT ) {
|
||||
assertSame( CharacterType.INSTANCE, nameAttribute.getType() );
|
||||
}else {
|
||||
}
|
||||
else {
|
||||
assertSame( CharacterNCharType.INSTANCE, nameAttribute.getType() );
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* 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.nationalized;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-10364")
|
||||
@RequiresDialectFeature(DialectChecks.SupportsNClob.class)
|
||||
public class NationalizedLobFieldTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {MyEntity.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNationalization() {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
try {
|
||||
MyEntity e = new MyEntity( 1L );
|
||||
e.setState( "UK" );
|
||||
s.save( e );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( s.getTransaction().getStatus() != TransactionStatus.FAILED_COMMIT ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = openSession();
|
||||
try {
|
||||
MyEntity myEntity = s.get( MyEntity.class, 1L );
|
||||
assertNotNull( myEntity );
|
||||
assertThat( myEntity.getState(), is( "UK" ) );
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Entity(name = "MyEntity")
|
||||
@Table(name = "my_entity")
|
||||
public static class MyEntity {
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Lob
|
||||
@Nationalized
|
||||
private String state;
|
||||
|
||||
public MyEntity() {
|
||||
}
|
||||
|
||||
public MyEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* 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.nationalized;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.hibernate.dialect.Oracle10gDialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "10495")
|
||||
@RequiresDialect(value = {Oracle10gDialect.class, PostgreSQL81Dialect.class})
|
||||
public class StringNationalizedTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {NationalizedEntity.class};
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
try {
|
||||
final Query query = s.createQuery( "delete from NationalizedEntity" );
|
||||
query.executeUpdate();
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if ( s.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveEntityWithNationalizedProperty() {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
try {
|
||||
NationalizedEntity ne = new NationalizedEntity();
|
||||
ne.name = "Hello";
|
||||
s.save( ne );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if ( s.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
|
||||
s = openSession();
|
||||
try {
|
||||
final Query query = s.createQuery( "from NationalizedEntity where name = :name" );
|
||||
query.setParameter( "name", "Hello" );
|
||||
final List list = query.list();
|
||||
assertThat( list.size(), is( 1 ) );
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "NationalizedEntity")
|
||||
@Table(name = "NATIONALIZED_ENTITY")
|
||||
public static class NationalizedEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
@Nationalized
|
||||
String name;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user