test cleanup
This commit is contained in:
parent
3f24a0064f
commit
e090480ea1
|
@ -331,7 +331,7 @@ public class BooleanMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||||
public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) {
|
public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) {
|
||||||
// Not strictly relevant to boolean mappings, but test that boolean
|
// Not strictly relevant to boolean mappings, but test that boolean
|
||||||
|
@ -350,7 +350,7 @@ public class BooleanMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||||
public void testBooleanFunctionInPredicate(SessionFactoryScope scope) {
|
public void testBooleanFunctionInPredicate(SessionFactoryScope scope) {
|
||||||
// Not strictly relevant to boolean mappings, but test that boolean
|
// Not strictly relevant to boolean mappings, but test that boolean
|
||||||
|
|
|
@ -6,222 +6,215 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.annotations.manytoonewithformula;
|
package org.hibernate.orm.test.annotations.manytoonewithformula;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.OracleDialect;
|
import org.hibernate.dialect.OracleDialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sharath Reddy
|
* @author Sharath Reddy
|
||||||
*/
|
*/
|
||||||
public class ManyToOneWithFormulaTest extends BaseCoreFunctionalTestCase {
|
@DomainModel( annotatedClasses = {
|
||||||
|
Menu.class,
|
||||||
|
FoodItem.class,
|
||||||
|
Company.class,
|
||||||
|
Person.class,
|
||||||
|
Message.class,
|
||||||
|
Language.class,
|
||||||
|
Contract.class,
|
||||||
|
ContractId.class,
|
||||||
|
Model.class,
|
||||||
|
ModelId.class,
|
||||||
|
Manufacturer.class,
|
||||||
|
ManufacturerId.class,
|
||||||
|
Product.class,
|
||||||
|
ProductSqlServer.class
|
||||||
|
} )
|
||||||
|
@SessionFactory
|
||||||
|
public class ManyToOneWithFormulaTest {
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneFromNonPk() throws Exception {
|
public void testManyToOneFromNonPk(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (session) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
Menu menu = new Menu();
|
||||||
Menu menu = new Menu();
|
menu.setOrderNbr( "123" );
|
||||||
menu.setOrderNbr( "123" );
|
menu.setDefault( "F" );
|
||||||
menu.setDefault( "F" );
|
session.persist( menu );
|
||||||
s.persist( menu );
|
FoodItem foodItem = new FoodItem();
|
||||||
FoodItem foodItem = new FoodItem();
|
foodItem.setItem( "Mouse" );
|
||||||
foodItem.setItem( "Mouse" );
|
foodItem.setOrder( menu );
|
||||||
foodItem.setOrder( menu );
|
session.persist( foodItem );
|
||||||
s.persist( foodItem );
|
session.flush();
|
||||||
s.flush();
|
session.clear();
|
||||||
s.clear();
|
|
||||||
foodItem = ( FoodItem ) s.get( FoodItem.class, foodItem.getId() );
|
foodItem = session.get( FoodItem.class, foodItem.getId() );
|
||||||
assertNotNull( foodItem.getOrder() );
|
assertThat( foodItem.getOrder() ).isNotNull();
|
||||||
assertEquals( "123", foodItem.getOrder().getOrderNbr() );
|
assertThat( foodItem.getOrder().getOrderNbr() ).isEqualTo( "123" );
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneFromPk() throws Exception {
|
public void testManyToOneFromPk(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (session) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
Company company = new Company();
|
||||||
|
session.persist( company );
|
||||||
|
|
||||||
Company company = new Company();
|
Person person = new Person();
|
||||||
s.persist( company );
|
person.setDefaultFlag( "T" );
|
||||||
|
person.setCompanyId( company.getId() );
|
||||||
|
session.persist( person );
|
||||||
|
|
||||||
Person person = new Person();
|
session.flush();
|
||||||
person.setDefaultFlag( "T" );
|
session.clear();
|
||||||
person.setCompanyId( company.getId() );
|
|
||||||
s.persist( person );
|
|
||||||
|
|
||||||
s.flush();
|
company = session.get( Company.class, company.getId() );
|
||||||
s.clear();
|
assertThat( company.getDefaultContactPerson() ).isNotNull();
|
||||||
|
assertThat( company.getDefaultContactPerson().getId() ).isEqualTo( person.getId() );
|
||||||
|
|
||||||
company = ( Company ) s.get( Company.class, company.getId() );
|
session.getTransaction().markRollbackOnly();
|
||||||
assertNotNull( company.getDefaultContactPerson() );
|
} );
|
||||||
assertEquals( person.getId(), company.getDefaultContactPerson().getId() );
|
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497")
|
@SkipForDialect( dialectClass = HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497" )
|
||||||
public void testManyToOneToPkWithOnlyFormula() throws Exception {
|
public void testManyToOneToPkWithOnlyFormula(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (session) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
Language language = new Language();
|
||||||
|
language.setCode( "EN" );
|
||||||
|
language.setName( "English" );
|
||||||
|
session.persist( language );
|
||||||
|
|
||||||
Language language = new Language();
|
Message msg = new Message();
|
||||||
language.setCode( "EN" );
|
msg.setLanguageCode( "en" );
|
||||||
language.setName( "English" );
|
msg.setLanguageName( "English" );
|
||||||
s.persist( language );
|
session.persist( msg );
|
||||||
|
|
||||||
Message msg = new Message();
|
session.flush();
|
||||||
msg.setLanguageCode( "en" );
|
session.clear();
|
||||||
msg.setLanguageName( "English" );
|
|
||||||
s.persist( msg );
|
|
||||||
|
|
||||||
s.flush();
|
msg = session.get( Message.class, msg.getId() );
|
||||||
s.clear();
|
assertThat( msg.getLanguage() ).isNotNull();
|
||||||
|
assertThat( msg.getLanguage().getCode() ).isEqualTo( "EN" );
|
||||||
|
|
||||||
msg = ( Message ) s.get( Message.class, msg.getId() );
|
session.getTransaction().markRollbackOnly();
|
||||||
assertNotNull( msg.getLanguage() );
|
} );
|
||||||
assertEquals( "EN", msg.getLanguage().getCode() );
|
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity() throws Exception {
|
public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity(SessionFactoryScope scope) {
|
||||||
Session session = openSession();
|
scope.inTransaction( (session) -> { Integer companyCode = 10;
|
||||||
Transaction tx = session.beginTransaction();
|
Integer mfgCode = 100;
|
||||||
|
String contractNumber = "NSAR97841";
|
||||||
|
ContractId contractId = new ContractId(companyCode, 12457l, 1);
|
||||||
|
|
||||||
Integer companyCode = 10;
|
Manufacturer manufacturer = new Manufacturer(new ManufacturerId(
|
||||||
Integer mfgCode = 100;
|
companyCode, mfgCode), "FORD");
|
||||||
String contractNumber = "NSAR97841";
|
|
||||||
ContractId contractId = new ContractId(companyCode, 12457l, 1);
|
|
||||||
|
|
||||||
Manufacturer manufacturer = new Manufacturer(new ManufacturerId(
|
Model model = new Model(new ModelId(companyCode, mfgCode, "FOCUS"),
|
||||||
companyCode, mfgCode), "FORD");
|
"FORD FOCUS");
|
||||||
|
|
||||||
Model model = new Model(new ModelId(companyCode, mfgCode, "FOCUS"),
|
session.persist(manufacturer);
|
||||||
"FORD FOCUS");
|
session.persist(model);
|
||||||
|
|
||||||
session.persist(manufacturer);
|
Contract contract = new Contract();
|
||||||
session.persist(model);
|
contract.setId(contractId);
|
||||||
|
contract.setContractNumber(contractNumber);
|
||||||
|
contract.setManufacturer(manufacturer);
|
||||||
|
contract.setModel(model);
|
||||||
|
|
||||||
Contract contract = new Contract();
|
session.persist(contract);
|
||||||
contract.setId(contractId);
|
|
||||||
contract.setContractNumber(contractNumber);
|
|
||||||
contract.setManufacturer(manufacturer);
|
|
||||||
contract.setModel(model);
|
|
||||||
|
|
||||||
session.persist(contract);
|
session.flush();
|
||||||
|
session.clear();
|
||||||
|
|
||||||
session.flush();
|
contract = session.get( Contract.class, contractId );
|
||||||
session.clear();
|
assertThat( contract.getContractNumber() ).isEqualTo( "NSAR97841" );
|
||||||
|
assertThat( contract.getManufacturer().getName() ).isEqualTo( "FORD" );
|
||||||
|
assertThat( contract.getModel().getName() ).isEqualTo( "FORD FOCUS" );
|
||||||
|
|
||||||
contract = (Contract) session.load(Contract.class, contractId);
|
session.getTransaction().markRollbackOnly();
|
||||||
assertEquals("NSAR97841", contract.getContractNumber());
|
} );
|
||||||
assertEquals("FORD", contract.getManufacturer().getName());
|
|
||||||
assertEquals("FORD FOCUS", contract.getModel().getName());
|
|
||||||
|
|
||||||
tx.commit();
|
|
||||||
session.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect( value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497." )
|
@SkipForDialect( dialectClass =HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497." )
|
||||||
@SkipForDialect( value = { OracleDialect.class }, comment = "Oracle do not support 'substring' function" )
|
@SkipForDialect( dialectClass = OracleDialect.class, reason = "Oracle do not support 'substring' function" )
|
||||||
public void testManyToOneFromNonPkToNonPk() throws Exception {
|
public void testManyToOneFromNonPkToNonPk(SessionFactoryScope scope) {
|
||||||
// also tests usage of the stand-alone @JoinFormula annotation (i.e. not wrapped within @JoinColumnsOrFormulas)
|
// also tests usage of the stand-alone @JoinFormula annotation
|
||||||
Session s = openSession();
|
// (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
Product kit = new Product();
|
scope.inTransaction( (session) -> {
|
||||||
kit.id = 1;
|
Product kit = new Product();
|
||||||
kit.productIdnf = "KIT";
|
kit.id = 1;
|
||||||
kit.description = "Kit";
|
kit.productIdnf = "KIT";
|
||||||
s.persist(kit);
|
kit.description = "Kit";
|
||||||
|
session.persist(kit);
|
||||||
|
|
||||||
Product kitkat = new Product();
|
Product kitkat = new Product();
|
||||||
kitkat.id = 2;
|
kitkat.id = 2;
|
||||||
kitkat.productIdnf = "KIT_KAT";
|
kitkat.productIdnf = "KIT_KAT";
|
||||||
kitkat.description = "Chocolate";
|
kitkat.description = "Chocolate";
|
||||||
s.persist(kitkat);
|
session.persist(kitkat);
|
||||||
|
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
|
|
||||||
kit = (Product) s.get(Product.class, 1);
|
kit = session.get(Product.class, 1);
|
||||||
kitkat = (Product) s.get(Product.class, 2);
|
kitkat = session.get(Product.class, 2);
|
||||||
System.out.println(kitkat.description);
|
|
||||||
assertNotNull(kitkat);
|
|
||||||
assertEquals(kit, kitkat.getProductFamily());
|
|
||||||
assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
|
|
||||||
assertEquals("KIT_KAT", kitkat.productIdnf.trim());
|
|
||||||
assertEquals("Chocolate", kitkat.description.trim());
|
|
||||||
|
|
||||||
tx.rollback();
|
assertThat( kitkat ).isNotNull();
|
||||||
s.close();
|
assertThat( kitkat.getProductFamily() ).isEqualTo( kit );
|
||||||
|
assertThat( kit.productIdnf ).isEqualTo( kitkat.getProductFamily().productIdnf );
|
||||||
|
assertThat( kitkat.productIdnf.trim() ).isEqualTo( "KIT_KAT" );
|
||||||
|
assertThat( kitkat.description.trim() ).isEqualTo( "Chocolate" );
|
||||||
|
|
||||||
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresDialect(value = { SQLServerDialect.class})
|
@RequiresDialect( SQLServerDialect.class )
|
||||||
public void testManyToOneFromNonPkToNonPkSqlServer() throws Exception {
|
public void testManyToOneFromNonPkToNonPkSqlServer(SessionFactoryScope scope) {
|
||||||
// also tests usage of the stand-alone @JoinFormula annotation (i.e. not wrapped within @JoinColumnsOrFormulas)
|
// also tests usage of the stand-alone @JoinFormula annotation
|
||||||
Session s = openSession();
|
// (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
ProductSqlServer kit = new ProductSqlServer();
|
scope.inTransaction( (session) -> {
|
||||||
kit.id = 1;
|
ProductSqlServer kit = new ProductSqlServer();
|
||||||
kit.productIdnf = "KIT";
|
kit.id = 1;
|
||||||
kit.description = "Kit";
|
kit.productIdnf = "KIT";
|
||||||
s.persist(kit);
|
kit.description = "Kit";
|
||||||
|
session.persist(kit);
|
||||||
|
|
||||||
ProductSqlServer kitkat = new ProductSqlServer();
|
ProductSqlServer kitkat = new ProductSqlServer();
|
||||||
kitkat.id = 2;
|
kitkat.id = 2;
|
||||||
kitkat.productIdnf = "KIT_KAT";
|
kitkat.productIdnf = "KIT_KAT";
|
||||||
kitkat.description = "Chocolate";
|
kitkat.description = "Chocolate";
|
||||||
s.persist(kitkat);
|
session.persist(kitkat);
|
||||||
|
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
|
|
||||||
kit = (ProductSqlServer) s.get(ProductSqlServer.class, 1);
|
kit = session.get(ProductSqlServer.class, 1);
|
||||||
kitkat = (ProductSqlServer) s.get(ProductSqlServer.class, 2);
|
kitkat = session.get(ProductSqlServer.class, 2);
|
||||||
System.out.println(kitkat.description);
|
|
||||||
assertNotNull(kitkat);
|
|
||||||
assertEquals(kit, kitkat.getProductFamily());
|
|
||||||
assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
|
|
||||||
assertEquals("KIT_KAT", kitkat.productIdnf.trim());
|
|
||||||
assertEquals("Chocolate", kitkat.description.trim());
|
|
||||||
|
|
||||||
tx.rollback();
|
assertThat( kitkat ).isNotNull();
|
||||||
s.close();
|
assertThat( kitkat.getProductFamily() ).isEqualTo( kit );
|
||||||
|
assertThat( kit.productIdnf ).isEqualTo( kitkat.getProductFamily().productIdnf );
|
||||||
|
assertThat( kitkat.productIdnf.trim() ).isEqualTo( "KIT_KAT" );
|
||||||
|
assertThat( kitkat.description.trim() ).isEqualTo( "Chocolate" );
|
||||||
|
|
||||||
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
Menu.class,
|
|
||||||
FoodItem.class,
|
|
||||||
Company.class,
|
|
||||||
Person.class,
|
|
||||||
Message.class,
|
|
||||||
Language.class,
|
|
||||||
Contract.class,
|
|
||||||
ContractId.class,
|
|
||||||
Model.class,
|
|
||||||
ModelId.class,
|
|
||||||
Manufacturer.class,
|
|
||||||
ManufacturerId.class,
|
|
||||||
Product.class,
|
|
||||||
ProductSqlServer.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.annotations.uniqueconstraint;
|
package org.hibernate.orm.test.annotations.uniqueconstraint;
|
||||||
|
|
||||||
import jakarta.persistence.PersistenceException;
|
|
||||||
|
|
||||||
import org.hibernate.JDBCException;
|
import org.hibernate.JDBCException;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.dialect.SybaseDialect;
|
import org.hibernate.dialect.SybaseDialect;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import jakarta.persistence.PersistenceException;
|
||||||
|
|
||||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
@ -23,52 +25,45 @@ import static org.junit.Assert.fail;
|
||||||
* @author Manuel Bernhardt
|
* @author Manuel Bernhardt
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
@SkipForDialect(value = SybaseDialect.class,
|
@DomainModel( annotatedClasses = { Room.class, Building.class, House.class } )
|
||||||
comment = "Sybase does not properly support unique constraints on nullable columns")
|
@SessionFactory
|
||||||
public class UniqueConstraintTest extends BaseCoreFunctionalTestCase {
|
@SkipForDialect( dialectClass = SybaseDialect.class,
|
||||||
|
reason = "Sybase does not properly support unique constraints on nullable columns" )
|
||||||
protected Class[] getAnnotatedClasses() {
|
public class UniqueConstraintTest {
|
||||||
return new Class[]{
|
|
||||||
Room.class,
|
|
||||||
Building.class,
|
|
||||||
House.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUniquenessConstraintWithSuperclassProperty() {
|
public void testUniquenessConstraintWithSuperclassProperty(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (s) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
Room livingRoom = new Room();
|
||||||
Room livingRoom = new Room();
|
livingRoom.setId(1l);
|
||||||
livingRoom.setId(1l);
|
livingRoom.setName("livingRoom");
|
||||||
livingRoom.setName("livingRoom");
|
s.persist(livingRoom);
|
||||||
s.persist(livingRoom);
|
|
||||||
s.flush();
|
|
||||||
House house = new House();
|
|
||||||
house.setId(1l);
|
|
||||||
house.setCost(100);
|
|
||||||
house.setHeight(1000l);
|
|
||||||
house.setRoom(livingRoom);
|
|
||||||
s.persist(house);
|
|
||||||
s.flush();
|
|
||||||
House house2 = new House();
|
|
||||||
house2.setId(2l);
|
|
||||||
house2.setCost(100);
|
|
||||||
house2.setHeight(1001l);
|
|
||||||
house2.setRoom(livingRoom);
|
|
||||||
s.persist(house2);
|
|
||||||
try {
|
|
||||||
s.flush();
|
s.flush();
|
||||||
fail( "Database constraint non-existent" );
|
House house = new House();
|
||||||
}
|
house.setId(1l);
|
||||||
catch (PersistenceException e) {
|
house.setCost(100);
|
||||||
assertTyping( JDBCException.class, e );
|
house.setHeight(1000l);
|
||||||
//success
|
house.setRoom(livingRoom);
|
||||||
}
|
s.persist(house);
|
||||||
finally {
|
s.flush();
|
||||||
tx.rollback();
|
House house2 = new House();
|
||||||
s.close();
|
house2.setId(2l);
|
||||||
}
|
house2.setCost(100);
|
||||||
|
house2.setHeight(1001l);
|
||||||
|
house2.setRoom(livingRoom);
|
||||||
|
s.persist(house2);
|
||||||
|
try {
|
||||||
|
s.flush();
|
||||||
|
fail( "Database constraint non-existent" );
|
||||||
|
}
|
||||||
|
catch (PersistenceException e) {
|
||||||
|
assertTyping( JDBCException.class, e );
|
||||||
|
//success
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
s.getTransaction().markRollbackOnly();
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,142 +9,130 @@ package org.hibernate.orm.test.annotations.xml.ejb3;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.dialect.CockroachDialect;
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-14529")
|
@TestForIssue(jiraKey = "HHH-14529")
|
||||||
public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(
|
||||||
|
annotatedClasses = { CarModel.class, Manufacturer.class, Model.class, Light.class },
|
||||||
@Override
|
xmlMappings = {
|
||||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
|
||||||
super.prepareBootstrapRegistryBuilder( builder );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SkipForDialect(value = {PostgreSQLDialect.class, CockroachDialect.class},
|
|
||||||
comment = "postgresql jdbc driver does not implement the setQueryTimeout method")
|
|
||||||
public void testEjb3Xml() throws Exception {
|
|
||||||
Session s = openSession();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
CarModel model = new CarModel();
|
|
||||||
model.setYear( new Date() );
|
|
||||||
Manufacturer manufacturer = new Manufacturer();
|
|
||||||
//s.persist( manufacturer );
|
|
||||||
model.setManufacturer( manufacturer );
|
|
||||||
manufacturer.getModels().add( model );
|
|
||||||
s.persist( model );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
model.setYear( new Date() );
|
|
||||||
manufacturer = (Manufacturer) s.get( Manufacturer.class, manufacturer.getId() );
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
|
||||||
.setParameter( "manufacturer", manufacturer )
|
|
||||||
.list();
|
|
||||||
assertEquals( 1, cars.size() );
|
|
||||||
for ( Model car : cars ) {
|
|
||||||
assertNotNull( car.getManufacturer() );
|
|
||||||
s.delete( manufacturer );
|
|
||||||
s.delete( car );
|
|
||||||
}
|
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testXMLEntityHandled() throws Exception {
|
|
||||||
Session s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
Lighter l = new Lighter();
|
|
||||||
l.name = "Blue";
|
|
||||||
l.power = "400F";
|
|
||||||
s.persist( l );
|
|
||||||
s.flush();
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testXmlDefaultOverriding() throws Exception {
|
|
||||||
Session s = openSession();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
Manufacturer manufacturer = new Manufacturer();
|
|
||||||
s.persist( manufacturer );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testMapXMLSupport() throws Exception {
|
|
||||||
Session s = openSession();
|
|
||||||
SessionFactory sf = s.getSessionFactory();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
// Verify that we can persist an object with a couple Map mappings
|
|
||||||
VicePresident vpSales = new VicePresident();
|
|
||||||
vpSales.name = "Dwight";
|
|
||||||
Company company = new Company();
|
|
||||||
company.conferenceRoomExtensions.put( "8932", "x1234" );
|
|
||||||
company.organization.put( "sales", vpSales );
|
|
||||||
s.persist( company );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
// For the element-collection, check that the orm.xml entries are honored.
|
|
||||||
// This includes: map-key-column/column/collection-table/join-column
|
|
||||||
BasicCollectionPersister confRoomMeta = (BasicCollectionPersister) sf
|
|
||||||
.unwrap( SessionFactoryImplementor.class )
|
|
||||||
.getMappingMetamodel()
|
|
||||||
.getCollectionDescriptor( Company.class.getName() + ".conferenceRoomExtensions" );
|
|
||||||
assertEquals( "company_id", confRoomMeta.getKeyColumnNames()[0] );
|
|
||||||
assertEquals( "phone_extension", confRoomMeta.getElementColumnNames()[0] );
|
|
||||||
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
|
||||||
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
CarModel.class,
|
|
||||||
Manufacturer.class,
|
|
||||||
Model.class,
|
|
||||||
Light.class
|
|
||||||
//Lighter.class xml only entuty
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String[] getOrmXmlFiles() {
|
|
||||||
return new String[] {
|
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm.xml",
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm.xml",
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm2.xml",
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm2.xml",
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm3.xml",
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm3.xml",
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm4.xml"
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm4.xml"
|
||||||
};
|
}
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class Ejb3XmlTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SkipForDialect( dialectClass = PostgreSQLDialect.class,
|
||||||
|
reason = "driver does not implement the setQueryTimeout method" )
|
||||||
|
@SkipForDialect( dialectClass = CockroachDialect.class,
|
||||||
|
reason = "driver does not implement the setQueryTimeout method" )
|
||||||
|
public void testEjb3Xml(SessionFactoryScope scope) {
|
||||||
|
scope.inSession( (s) -> {
|
||||||
|
s.getTransaction().begin();
|
||||||
|
|
||||||
|
CarModel model = new CarModel();
|
||||||
|
model.setYear( new Date() );
|
||||||
|
Manufacturer manufacturer = new Manufacturer();
|
||||||
|
//s.persist( manufacturer );
|
||||||
|
model.setManufacturer( manufacturer );
|
||||||
|
manufacturer.getModels().add( model );
|
||||||
|
s.persist( model );
|
||||||
|
s.flush();
|
||||||
|
s.clear();
|
||||||
|
|
||||||
|
model.setYear( new Date() );
|
||||||
|
manufacturer = s.get( Manufacturer.class, manufacturer.getId() );
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
||||||
|
.setParameter( "manufacturer", manufacturer )
|
||||||
|
.list();
|
||||||
|
assertEquals( 1, cars.size() );
|
||||||
|
for ( Model car : cars ) {
|
||||||
|
Assertions.assertNotNull( car.getManufacturer() );
|
||||||
|
s.remove( manufacturer );
|
||||||
|
s.remove( car );
|
||||||
|
}
|
||||||
|
|
||||||
|
s.getTransaction().rollback();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testXMLEntityHandled(SessionFactoryScope scope) {
|
||||||
|
scope.inSession( (s) -> {
|
||||||
|
s.getTransaction().begin();
|
||||||
|
Lighter l = new Lighter();
|
||||||
|
l.name = "Blue";
|
||||||
|
l.power = "400F";
|
||||||
|
s.persist( l );
|
||||||
|
s.flush();
|
||||||
|
s.getTransaction().rollback();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testXmlDefaultOverriding(SessionFactoryScope scope) {
|
||||||
|
scope.inSession( (s) -> {
|
||||||
|
Transaction tx = s.beginTransaction();
|
||||||
|
Manufacturer manufacturer = new Manufacturer();
|
||||||
|
s.persist( manufacturer );
|
||||||
|
s.flush();
|
||||||
|
s.clear();
|
||||||
|
|
||||||
|
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
||||||
|
|
||||||
|
tx.rollback();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testMapXMLSupport(SessionFactoryScope scope) {
|
||||||
|
scope.inSession( (s) -> {
|
||||||
|
SessionFactoryImplementor sf = s.getSessionFactory();
|
||||||
|
Transaction tx = s.beginTransaction();
|
||||||
|
|
||||||
|
// Verify that we can persist an object with a couple Map mappings
|
||||||
|
VicePresident vpSales = new VicePresident();
|
||||||
|
vpSales.name = "Dwight";
|
||||||
|
Company company = new Company();
|
||||||
|
company.conferenceRoomExtensions.put( "8932", "x1234" );
|
||||||
|
company.organization.put( "sales", vpSales );
|
||||||
|
s.persist( company );
|
||||||
|
s.flush();
|
||||||
|
s.clear();
|
||||||
|
|
||||||
|
// For the element-collection, check that the orm.xml entries are honored.
|
||||||
|
// This includes: map-key-column/column/collection-table/join-column
|
||||||
|
BasicCollectionPersister confRoomMeta = (BasicCollectionPersister) sf
|
||||||
|
.unwrap( SessionFactoryImplementor.class )
|
||||||
|
.getMappingMetamodel()
|
||||||
|
.getCollectionDescriptor( Company.class.getName() + ".conferenceRoomExtensions" );
|
||||||
|
assertEquals( "company_id", confRoomMeta.getKeyColumnNames()[0] );
|
||||||
|
assertEquals( "phone_extension", confRoomMeta.getElementColumnNames()[0] );
|
||||||
|
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
||||||
|
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
||||||
|
tx.rollback();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.CockroachDialect;
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.dialect.OracleDialect;
|
import org.hibernate.dialect.OracleDialect;
|
||||||
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue