Re-enable additional tests

This commit is contained in:
Andrea Boriero 2021-11-25 09:48:44 +01:00 committed by Andrea Boriero
parent 9766b05eba
commit 492d391e73
40 changed files with 554 additions and 545 deletions

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.dataTypes; package org.hibernate.orm.test.annotations.dataTypes;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
@ -14,81 +14,98 @@ import java.sql.Statement;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.testing.DialectCheck;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.type.descriptor.JdbcTypeNameMapper; import org.hibernate.type.descriptor.JdbcTypeNameMapper;
import static org.junit.Assert.assertEquals; import org.hibernate.testing.orm.junit.DialectFeatureCheck;
import static org.junit.Assert.assertTrue; 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.RequiresDialectFeatureGroup;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@RequiresDialectFeature(value = {DialectChecks.SupportsExpectedLobUsagePattern.class, BasicOperationsTest.OracleDialectChecker.class}, jiraKey = "HHH-6834") @RequiresDialectFeatureGroup(
public class BasicOperationsTest extends BaseCoreFunctionalTestCase { value = {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExpectedLobUsagePattern.class),
@RequiresDialectFeature(feature = BasicOperationsTest.OracleDialectChecker.class)
},
jiraKey = "HHH-6834"
)
@DomainModel(
annotatedClasses = { SomeEntity.class, SomeOtherEntity.class }
)
@SessionFactory
public class BasicOperationsTest {
private static final String SOME_ENTITY_TABLE_NAME = "SOMEENTITY"; private static final String SOME_ENTITY_TABLE_NAME = "SOMEENTITY";
private static final String SOME_OTHER_ENTITY_TABLE_NAME = "SOMEOTHERENTITY"; private static final String SOME_OTHER_ENTITY_TABLE_NAME = "SOMEOTHERENTITY";
public static class OracleDialectChecker implements DialectFeatureCheck {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { public boolean apply(Dialect dialect) {
return new Class[] { SomeEntity.class, SomeOtherEntity.class }; return !( dialect instanceof OracleDialect );
}
public static class OracleDialectChecker implements DialectCheck{
@Override
public boolean isMatch(Dialect dialect) {
return ! (dialect instanceof Oracle8iDialect);
} }
} }
@Test @Test
public void testCreateAndDelete() { public void testCreateAndDelete(SessionFactoryScope scope) {
Date now = new Date(); Date now = new Date();
Session s = openSession();
s.doWork( new ValidateSomeEntityColumns( (SessionImplementor) s ) );
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_ENTITY_TABLE_NAME, 0 ) );
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
s.beginTransaction();
SomeEntity someEntity = new SomeEntity( now ); SomeEntity someEntity = new SomeEntity( now );
SomeOtherEntity someOtherEntity = new SomeOtherEntity( 1 ); SomeOtherEntity someOtherEntity = new SomeOtherEntity( 1 );
s.save( someEntity );
s.save( someOtherEntity );
s.getTransaction().commit();
s.close();
s = openSession(); scope.inTransaction(
session -> {
session.doWork( new ValidateSomeEntityColumns( session ) );
session.doWork( new ValidateRowCount( session, SOME_ENTITY_TABLE_NAME, 0 ) );
session.doWork( new ValidateRowCount( session, SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_ENTITY_TABLE_NAME, 1 ) ); session.save( someEntity );
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_OTHER_ENTITY_TABLE_NAME, 1 ) ); session.save( someOtherEntity );
}
);
s.beginTransaction(); scope.inSession(
s.delete( someEntity ); session -> {
s.delete( someOtherEntity ); session.doWork( new ValidateRowCount( session, SOME_ENTITY_TABLE_NAME, 1 ) );
s.getTransaction().commit(); session.doWork( new ValidateRowCount( session, SOME_OTHER_ENTITY_TABLE_NAME, 1 ) );
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_ENTITY_TABLE_NAME, 0 ) ); try {
s.doWork( new ValidateRowCount( (SessionImplementor) s, SOME_OTHER_ENTITY_TABLE_NAME, 0 ) ); session.beginTransaction();
s.close(); session.delete( someEntity );
session.delete( someOtherEntity );
session.getTransaction().commit();
}
finally {
if ( session.getTransaction().isActive() ) {
session.getTransaction().rollback();
}
}
session.doWork( new ValidateRowCount( session, SOME_ENTITY_TABLE_NAME, 0 ) );
session.doWork( new ValidateRowCount( session, SOME_OTHER_ENTITY_TABLE_NAME, 0 ) );
}
);
} }
// verify all the expected columns are created // verify all the expected columns are created
class ValidateSomeEntityColumns implements Work { class ValidateSomeEntityColumns implements Work {
private SessionImplementor s; private SessionImplementor s;
public ValidateSomeEntityColumns( SessionImplementor s ) { public ValidateSomeEntityColumns(SessionImplementor s) {
this.s = s; this.s = s;
} }
@ -113,20 +130,20 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase {
String columnNamePattern = generateFinalNamePattern( meta, columnName ); String columnNamePattern = generateFinalNamePattern( meta, columnName );
ResultSet columnInfo = meta.getColumns( null, null, tableNamePattern, columnNamePattern ); ResultSet columnInfo = meta.getColumns( null, null, tableNamePattern, columnNamePattern );
s.getJdbcCoordinator().getResourceRegistry().register(columnInfo, columnInfo.getStatement()); s.getJdbcCoordinator().getResourceRegistry().register( columnInfo, columnInfo.getStatement() );
assertTrue( columnInfo.next() ); assertTrue( columnInfo.next() );
int dataType = columnInfo.getInt( "DATA_TYPE" ); int dataType = columnInfo.getInt( "DATA_TYPE" );
s.getJdbcCoordinator().getResourceRegistry().release( columnInfo, columnInfo.getStatement() ); s.getJdbcCoordinator().getResourceRegistry().release( columnInfo, columnInfo.getStatement() );
assertEquals( assertEquals(
columnName,
JdbcTypeNameMapper.getTypeName( expectedJdbcTypeCode ), JdbcTypeNameMapper.getTypeName( expectedJdbcTypeCode ),
JdbcTypeNameMapper.getTypeName( dataType ) JdbcTypeNameMapper.getTypeName( dataType ),
columnName
); );
} }
private String generateFinalNamePattern(DatabaseMetaData meta, String name) throws SQLException { private String generateFinalNamePattern(DatabaseMetaData meta, String name) throws SQLException {
if ( meta.storesLowerCaseIdentifiers() ) { if ( meta.storesLowerCaseIdentifiers() ) {
return name.toLowerCase(Locale.ROOT); return name.toLowerCase( Locale.ROOT );
} }
else { else {
return name; return name;
@ -150,10 +167,13 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase {
public void execute(Connection connection) throws SQLException { public void execute(Connection connection) throws SQLException {
Statement st = s.getJdbcCoordinator().getStatementPreparer().createStatement(); Statement st = s.getJdbcCoordinator().getStatementPreparer().createStatement();
s.getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table ); s.getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table );
ResultSet result = s.getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table ); ResultSet result = s.getJdbcCoordinator().getResultSetReturn().extract(
st,
"SELECT COUNT(*) FROM " + table
);
result.next(); result.next();
int rowCount = result.getInt( 1 ); int rowCount = result.getInt( 1 );
assertEquals( "Unexpected row count", expectedRowCount, rowCount ); assertEquals( expectedRowCount, rowCount, "Unexpected row count" );
} }
} }
} }

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.dataTypes; package org.hibernate.orm.test.annotations.dataTypes;
/** /**

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.dataTypes; package org.hibernate.orm.test.annotations.dataTypes;
import java.util.Date; import java.util.Date;
import jakarta.persistence.Access; import jakarta.persistence.Access;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.dataTypes; package org.hibernate.orm.test.annotations.dataTypes;
import jakarta.persistence.Access; import jakarta.persistence.Access;
import jakarta.persistence.AccessType; import jakarta.persistence.AccessType;

View File

@ -4,9 +4,18 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.notfound; package org.hibernate.orm.test.annotations.notfound;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ConstraintMode; import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
@ -16,43 +25,40 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import org.hibernate.annotations.NotFound; import static org.junit.jupiter.api.Assertions.assertNull;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNull;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
* @author Gail Badner * @author Gail Badner
*/ */
public class NotFoundLogicalOneToOneTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = { NotFoundLogicalOneToOneTest.Coin.class, NotFoundLogicalOneToOneTest.Currency.class }
)
@SessionFactory
public class NotFoundLogicalOneToOneTest {
@Test @Test
public void testLogicalOneToOne() throws Exception { public void testLogicalOneToOne(SessionFactoryScope scope) {
Currency euro = new Currency(); Currency euro = new Currency();
euro.setName( "Euro" ); euro.setName( "Euro" );
Coin fiveC = new Coin(); Coin fiveC = new Coin();
fiveC.setName( "Five cents" ); fiveC.setName( "Five cents" );
fiveC.setCurrency( euro ); fiveC.setCurrency( euro );
doInHibernate( scope.inTransaction(
this::sessionFactory, session -> { session -> {
session.persist( euro ); session.persist( euro );
session.persist( fiveC ); session.persist( fiveC );
} }
); );
doInHibernate( scope.inTransaction(
this::sessionFactory, session -> { session ->
session.delete( euro ); session.delete( euro )
}
); );
doInHibernate( scope.inTransaction(
this::sessionFactory, session -> { session -> {
Coin coin = session.get( Coin.class, fiveC.getId() ); Coin coin = session.get( Coin.class, fiveC.getId() );
assertNull( coin.getCurrency() ); assertNull( coin.getCurrency() );
@ -61,11 +67,6 @@ public class NotFoundLogicalOneToOneTest extends BaseCoreFunctionalTestCase {
); );
} }
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] { Coin.class, Currency.class };
}
@Entity(name = "Coin") @Entity(name = "Coin")
public static class Coin { public static class Coin {
private Integer id; private Integer id;

View File

@ -4,7 +4,15 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.notfound; package org.hibernate.orm.test.annotations.notfound;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -12,35 +20,28 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import org.hibernate.annotations.NotFound; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.hibernate.annotations.NotFoundAction; import static org.junit.jupiter.api.Assertions.assertNull;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class NotFoundOneToOneNonInsertableNonUpdateableTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
NotFoundOneToOneNonInsertableNonUpdateableTest.Person.class,
NotFoundOneToOneNonInsertableNonUpdateableTest.PersonInfo.class
}
)
@SessionFactory
public class NotFoundOneToOneNonInsertableNonUpdateableTest {
private static final int ID = 1; private static final int ID = 1;
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
Person.class,
PersonInfo.class
};
}
@Test @Test
public void testOneToOne() { public void testOneToOne(SessionFactoryScope scope) {
doInHibernate( scope.inTransaction(
this::sessionFactory, session -> { session -> {
Person person = new Person(); Person person = new Person();
person.id = ID; person.id = ID;
person.personInfo = new PersonInfo(); person.personInfo = new PersonInfo();
@ -49,14 +50,13 @@ public class NotFoundOneToOneNonInsertableNonUpdateableTest extends BaseCoreFunc
} }
); );
doInHibernate( scope.inTransaction(
this::sessionFactory, session -> { session ->
session.delete( session.get( PersonInfo.class, ID ) ); session.delete( session.get( PersonInfo.class, ID ) )
}
); );
doInHibernate( scope.inTransaction(
this::sessionFactory, session -> { session -> {
Person person = session.get( Person.class, ID ); Person person = session.get( Person.class, ID );
assertNotNull( person ); assertNotNull( person );
assertNull( person.personInfo ); assertNull( person.personInfo );
@ -66,7 +66,7 @@ public class NotFoundOneToOneNonInsertableNonUpdateableTest extends BaseCoreFunc
); );
} }
@Entity(name="Person") @Entity(name = "Person")
public static class Person { public static class Person {
@Id @Id

View File

@ -4,34 +4,41 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.notfound; package org.hibernate.orm.test.annotations.notfound;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
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.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import org.hibernate.annotations.NotFound; import static org.junit.jupiter.api.Assertions.assertNull;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNull;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@RequiresDialectFeature(value = DialectChecks.SupportsIdentityColumns.class) @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
public class NotFoundTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = { NotFoundTest.Coin.class, NotFoundTest.Currency.class }
)
@SessionFactory
public class NotFoundTest {
@Test @Test
public void testManyToOne() throws Exception { public void testManyToOne(SessionFactoryScope scope) {
final Currency euro = new Currency(); final Currency euro = new Currency();
euro.setName( "Euro" ); euro.setName( "Euro" );
@ -39,28 +46,23 @@ public class NotFoundTest extends BaseCoreFunctionalTestCase {
fiveCents.setName( "Five cents" ); fiveCents.setName( "Five cents" );
fiveCents.setCurrency( euro ); fiveCents.setCurrency( euro );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.persist( euro ); session.persist( euro );
session.persist( fiveCents ); session.persist( fiveCents );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
Currency _euro = session.get( Currency.class, euro.getId() ); Currency _euro = session.get( Currency.class, euro.getId() );
session.delete( _euro ); session.delete( _euro );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
Coin _fiveCents = session.get( Coin.class, fiveCents.getId() ); Coin _fiveCents = session.get( Coin.class, fiveCents.getId() );
assertNull( _fiveCents.getCurrency() ); assertNull( _fiveCents.getCurrency() );
session.delete( _fiveCents ); session.delete( _fiveCents );
} ); } );
} }
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {Coin.class, Currency.class};
}
@Entity(name = "Coin") @Entity(name = "Coin")
public static class Coin { public static class Coin {

View File

@ -4,7 +4,18 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.annotations.notfound; package org.hibernate.orm.test.annotations.notfound;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
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.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -16,47 +27,37 @@ import jakarta.persistence.JoinTable;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.annotations.NotFound; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.hibernate.annotations.NotFoundAction; import static org.junit.jupiter.api.Assertions.assertNull;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/** /**
* @author Andrea Boriero * @author Andrea Boriero
*/ */
@TestForIssue(jiraKey = "HHH-11591") @TestForIssue(jiraKey = "HHH-11591")
public class OneToOneNotFoundTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = { OneToOneNotFoundTest.Show.class, OneToOneNotFoundTest.ShowDescription.class }
)
@SessionFactory(
exportSchema = false
)
public class OneToOneNotFoundTest {
@Override @BeforeEach
protected boolean createSchema() { public void setUp(SessionFactoryScope scope) {
return false; scope.inTransaction(
} session ->
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {Show.class, ShowDescription.class};
}
@Before
public void setUp() {
doInHibernate( this::sessionFactory, session -> {
session.doWork( connection -> { session.doWork( connection -> {
connection.createStatement().execute("create table SHOW_DESCRIPTION ( ID integer not null, primary key (ID) )" ); connection.createStatement().execute(
connection.createStatement().execute("create table T_SHOW ( id integer not null, primary key (id) )" ); "create table SHOW_DESCRIPTION ( ID integer not null, primary key (ID) )" );
connection.createStatement().execute("create table TSHOW_SHOWDESCRIPTION ( DESCRIPTION_ID integer, SHOW_ID integer not null, primary key (SHOW_ID) )" ); connection.createStatement().execute(
"create table T_SHOW ( id integer not null, primary key (id) )" );
connection.createStatement().execute(
"create table TSHOW_SHOWDESCRIPTION ( DESCRIPTION_ID integer, SHOW_ID integer not null, primary key (SHOW_ID) )" );
} ); } )
} ); );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
Show show = new Show(); Show show = new Show();
show.setId( 1 ); show.setId( 1 );
ShowDescription showDescription = new ShowDescription(); ShowDescription showDescription = new ShowDescription();
@ -67,29 +68,31 @@ public class OneToOneNotFoundTest extends BaseCoreFunctionalTestCase {
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction(
session.doWork( connection -> { session ->
connection.createStatement().execute( "delete from SHOW_DESCRIPTION where ID = 2" ); session.doWork( connection ->
connection.createStatement()
} ); .execute( "delete from SHOW_DESCRIPTION where ID = 2" )
} ); )
);
} }
@After @AfterEach
public void tearDow() { public void tearDow(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction(
session ->
session.doWork( connection -> { session.doWork( connection -> {
connection.createStatement().execute( "drop table TSHOW_SHOWDESCRIPTION" ); connection.createStatement().execute( "drop table TSHOW_SHOWDESCRIPTION" );
connection.createStatement().execute( "drop table SHOW_DESCRIPTION" ); connection.createStatement().execute( "drop table SHOW_DESCRIPTION" );
connection.createStatement().execute( "drop table T_SHOW" ); connection.createStatement().execute( "drop table T_SHOW" );
} ); } )
} ); );
} }
@Test @Test
public void testOneToOne() throws Exception { public void testOneToOne(SessionFactoryScope scope) throws Exception {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
final Show show2 = session.find( Show.class, 1 ); final Show show2 = session.find( Show.class, 1 );
assertNotNull( show2 ); assertNotNull( show2 );
assertNull( show2.getDescription() ); assertNull( show2.getDescription() );

View File

@ -0,0 +1,67 @@
/*
* 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.query;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
/**
* @author Vlad Mihalcea
*/
@DomainModel(
annotatedClasses = NativeQueryWithParenthesesTest.Person.class
)
@SessionFactory
public class NativeQueryWithParenthesesTest {
@Test
public void testParseParentheses(SessionFactoryScope scope) {
scope.inTransaction(
entityManager ->
entityManager.createNativeQuery(
"(SELECT p.id, p.name FROM Person p WHERE p.name LIKE 'A%') " +
"UNION " +
"(SELECT p.id, p.name FROM Person p WHERE p.name LIKE 'B%')",
Person.class
).getResultList()
);
}
@Entity
@Table(name = "Person")
public static class Person {
@Id
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
public class EwtAssessmentExtension extends SettlementExtension { public class EwtAssessmentExtension extends SettlementExtension {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
import java.util.Date; import java.util.Date;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
public class GapAssessmentExtension extends SettlementExtension { public class GapAssessmentExtension extends SettlementExtension {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;

View File

@ -0,0 +1,92 @@
/*
* 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.query.hhh12076;
import java.util.List;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@TestForIssue(jiraKey = "HHH-12076")
@DomainModel(
xmlMappings = {
"org/hibernate/query/hhh12076/Claim.hbm.xml",
"org/hibernate/query/hhh12076/EwtAssessmentExtension.hbm.xml",
"org/hibernate/query/hhh12076/Extension.hbm.xml",
"org/hibernate/query/hhh12076/GapAssessmentExtension.hbm.xml",
"org/hibernate/query/hhh12076/Settlement.hbm.xml",
"org/hibernate/query/hhh12076/SettlementExtension.hbm.xml",
"org/hibernate/query/hhh12076/SettlementTask.hbm.xml",
"org/hibernate/query/hhh12076/Task.hbm.xml",
"org/hibernate/query/hhh12076/TaskStatus.hbm.xml",
}
)
@SessionFactory
public class HbmMappingJoinClassTest {
@BeforeEach
protected void prepareTest(SessionFactoryScope scope) {
scope.inTransaction( session -> {
TaskStatus taskStatus = new TaskStatus();
taskStatus.setName( "Enabled" );
taskStatus.setDisplayName( "Enabled" );
session.save( taskStatus );
for ( long i = 0; i < 10; i++ ) {
SettlementTask settlementTask = new SettlementTask();
settlementTask.setId( i );
Settlement settlement = new Settlement();
settlementTask.setLinked( settlement );
settlementTask.setStatus( taskStatus );
Claim claim = new Claim();
claim.setId( i );
settlement.setClaim( claim );
for ( int j = 0; j < 2; j++ ) {
GapAssessmentExtension gapAssessmentExtension = new GapAssessmentExtension();
gapAssessmentExtension.setSettlement( settlement );
EwtAssessmentExtension ewtAssessmentExtension = new EwtAssessmentExtension();
ewtAssessmentExtension.setSettlement( settlement );
settlement.getExtensions().add( gapAssessmentExtension );
settlement.getExtensions().add( ewtAssessmentExtension );
}
session.save( claim );
session.save( settlement );
session.save( settlementTask );
}
} );
}
@Test
public void testClassExpressionInOnClause(SessionFactoryScope scope) {
scope.inTransaction( session -> {
List<SettlementTask> results = session.createQuery(
"select " +
" rootAlias.id, " +
" linked.id, " +
" extensions.id " +
"from SettlementTask as rootAlias " +
"join rootAlias.linked as linked " +
"left join linked.extensions as extensions " +
" on extensions.class = org.hibernate.orm.test.query.hhh12076.EwtAssessmentExtension " +
"where linked.id = :claimId" )
.setParameter( "claimId", 1L )
.getResultList();
assertNotNull( results );
} );
}
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
import java.util.Date; import java.util.Date;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
public enum SettlementStatus { public enum SettlementStatus {
RESERVED, ALLOCATED, PAID, VOID, DENIED RESERVED, ALLOCATED, PAID, VOID, DENIED

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
public class SettlementTask extends Task<Settlement> { public class SettlementTask extends Task<Settlement> {

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12076; package org.hibernate.orm.test.query.hhh12076;
import java.util.Date; import java.util.Date;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12225; package org.hibernate.orm.test.query.hhh12225;
import java.util.Date; import java.util.Date;

View File

@ -4,43 +4,33 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12225; package org.hibernate.orm.test.query.hhh12225;
import java.util.List; import java.util.List;
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.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
@TestForIssue(jiraKey = "HHH-12225") @TestForIssue(jiraKey = "HHH-12225")
public class HQLTypeTest extends BaseCoreFunctionalTestCase { @DomainModel(
xmlMappings = {
@Override "org/hibernate/orm/test/query/hhh12225/Contract.hbm.xml",
protected Class[] getAnnotatedClasses() { "org/hibernate/orm/test/query/hhh12225/Vehicle.hbm.xml"
return new Class[] {
};
}
@Override
protected String[] getMappings() {
return new String[] {
"Contract.hbm.xml",
"Vehicle.hbm.xml"
};
}
@Override
protected String getBaseForMappings() {
return "org/hibernate/query/hhh12225/";
} }
)
@SessionFactory
public class HQLTypeTest {
@Test @Test
public void test() throws Exception { public void test(SessionFactoryScope scope) {
VehicleContract contract = doInHibernate( this::sessionFactory, session -> { VehicleContract contract = scope.fromTransaction( session -> {
VehicleContract firstCotract = null; VehicleContract firstCotract = null;
for ( long i = 0; i < 10; i++ ) { for ( long i = 0; i < 10; i++ ) {
VehicleContract vehicleContract = new VehicleContract(); VehicleContract vehicleContract = new VehicleContract();
@ -61,7 +51,7 @@ public class HQLTypeTest extends BaseCoreFunctionalTestCase {
return firstCotract; return firstCotract;
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
List workingResults = session.createQuery( List workingResults = session.createQuery(
"select rootAlias.id from Contract as rootAlias where rootAlias.id = :id" ) "select rootAlias.id from Contract as rootAlias where rootAlias.id = :id" )
.setParameter( "id", contract.getId() ) .setParameter( "id", contract.getId() )
@ -69,7 +59,7 @@ public class HQLTypeTest extends BaseCoreFunctionalTestCase {
assertFalse( workingResults.isEmpty() ); assertFalse( workingResults.isEmpty() );
Long workingId = (Long) workingResults.get( 0 ); Long workingId = (Long) workingResults.get( 0 );
assertEquals( Long.valueOf( contract.getId() ), workingId ); assertEquals( contract.getId(), workingId );
List failingResults = session.createQuery( List failingResults = session.createQuery(
"select rootAlias.id, type(rootAlias) from Contract as rootAlias where rootAlias.id = :id" ) "select rootAlias.id, type(rootAlias) from Contract as rootAlias where rootAlias.id = :id" )
@ -78,7 +68,7 @@ public class HQLTypeTest extends BaseCoreFunctionalTestCase {
assertFalse( failingResults.isEmpty() ); assertFalse( failingResults.isEmpty() );
Long failingId = (Long) ( (Object[]) failingResults.get( 0 ) )[0]; Long failingId = (Long) ( (Object[]) failingResults.get( 0 ) )[0];
assertEquals( Long.valueOf( contract.getId() ), failingId ); assertEquals( contract.getId(), failingId );
} ); } );
} }
} }

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12225; package org.hibernate.orm.test.query.hhh12225;
import java.util.Date; import java.util.Date;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12225; package org.hibernate.orm.test.query.hhh12225;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.query.hhh12225; package org.hibernate.orm.test.query.hhh12225;
public class VehicleTrackContract extends VehicleContract { public class VehicleTrackContract extends VehicleContract {
public static final long serialVersionUID = 1L; public static final long serialVersionUID = 1L;

View File

@ -0,0 +1,125 @@
/*
* 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.query.hhh13712;
import java.util.List;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import static org.junit.jupiter.api.Assertions.assertEquals;
@TestForIssue(jiraKey = "HHH-13712")
@Jpa(
annotatedClasses = { HHH13712Test.Super.class, HHH13712Test.SubObject.class, HHH13712Test.SomeOther.class }
)
public class HHH13712Test {
@BeforeAll
public void setUp(EntityManagerFactoryScope scope) {
scope.inTransaction( em -> {
SomeOther a_1 = new SomeOther( 1L );
SomeOther a_2 = new SomeOther( 2L );
SomeOther a_3 = new SomeOther( 3L );
SubObject b_5 = new SubObject( 5L, a_1 );
SubObject b_6 = new SubObject( 6L, a_2 );
SubObject b_7 = new SubObject( 7L, a_3 );
em.merge( a_1 );
em.merge( a_2 );
em.merge( a_3 );
em.merge( b_5 );
em.merge( b_6 );
em.merge( b_7 );
} );
}
@Test
public void testJoinSuperclassAssociationOnly(EntityManagerFactoryScope scope) {
scope.inTransaction( em -> {
List<Integer> actual = em.createQuery( "SELECT 1 FROM SubObject sub LEFT JOIN sub.parent p", Integer.class )
.getResultList();
assertEquals( 3, actual.size() );
} );
}
@Test
public void testJoinSuperclassAssociation(EntityManagerFactoryScope scope) {
scope.inTransaction( em -> {
long actual = em.createQuery(
"SELECT COUNT(sub) FROM SubObject sub LEFT JOIN sub.parent p WHERE p.id = 1",
Long.class
).getSingleResult();
assertEquals( 1L, actual );
} );
}
@Test
public void testCountParentIds(EntityManagerFactoryScope scope) {
scope.inTransaction( em -> {
long actual = em.createQuery( "SELECT COUNT(distinct sub.parent.id) FROM SubObject sub", Long.class )
.getSingleResult();
assertEquals( 3L, actual );
} );
}
@Entity(name = "Super")
@Inheritance(strategy = InheritanceType.JOINED)
public static class Super {
@Id
@Column
Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false)
SomeOther parent;
}
@Entity(name = "SubObject")
public static class SubObject extends Super {
SubObject() {
}
SubObject(Long id, SomeOther parent) {
this.id = id;
this.parent = parent;
}
}
@Entity(name = "SomeOther")
public static class SomeOther {
@Id
@Column
Long id;
SomeOther() {
}
SomeOther(Long id) {
this.id = id;
}
}
}

View File

@ -1,68 +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.query;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Vlad Mihalcea
*/
public class NativeQueryWithParenthesesTest extends BaseEntityManagerFunctionalTestCase {
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
Person.class
};
}
@Test
public void testParseParentheses() {
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.createNativeQuery(
"(SELECT p.id, p.name FROM Person p WHERE p.name LIKE 'A%') " +
"UNION " +
"(SELECT p.id, p.name FROM Person p WHERE p.name LIKE 'B%')", Person.class)
.getResultList();
} );
}
@Entity
@Table(name = "Person")
public static class Person {
@Id
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -1,101 +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.query.hhh12076;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@TestForIssue(jiraKey = "HHH-12076")
public class HbmMappingJoinClassTest extends BaseCoreFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[] {
"Claim.hbm.xml",
"EwtAssessmentExtension.hbm.xml",
"Extension.hbm.xml",
"GapAssessmentExtension.hbm.xml",
"Settlement.hbm.xml",
"SettlementExtension.hbm.xml",
"SettlementTask.hbm.xml",
"Task.hbm.xml",
"TaskStatus.hbm.xml",
};
}
@Override
protected String getBaseForMappings() {
return "org/hibernate/query/hhh12076/";
}
@Override
protected void prepareTest() {
doInHibernate( this::sessionFactory, session -> {
TaskStatus taskStatus = new TaskStatus();
taskStatus.setName("Enabled");
taskStatus.setDisplayName("Enabled");
session.save(taskStatus);
for (long i = 0; i < 10; i++) {
SettlementTask settlementTask = new SettlementTask();
settlementTask.setId(i);
Settlement settlement = new Settlement();
settlementTask.setLinked(settlement);
settlementTask.setStatus(taskStatus);
Claim claim = new Claim();
claim.setId(i);
settlement.setClaim(claim);
for (int j = 0; j < 2; j++) {
GapAssessmentExtension gapAssessmentExtension = new GapAssessmentExtension();
gapAssessmentExtension.setSettlement(settlement);
EwtAssessmentExtension ewtAssessmentExtension = new EwtAssessmentExtension();
ewtAssessmentExtension.setSettlement(settlement);
settlement.getExtensions().add(gapAssessmentExtension);
settlement.getExtensions().add(ewtAssessmentExtension);
}
session.save(claim);
session.save(settlement);
session.save(settlementTask);
}
} );
}
@Test
public void testClassExpressionInOnClause() {
doInHibernate( this::sessionFactory, session -> {
List<SettlementTask> results = session.createQuery(
"select " +
" rootAlias.id, " +
" linked.id, " +
" extensions.id " +
"from SettlementTask as rootAlias " +
"join rootAlias.linked as linked " +
"left join linked.extensions as extensions " +
" on extensions.class = org.hibernate.query.hhh12076.EwtAssessmentExtension " +
"where linked.id = :claimId")
.setParameter("claimId", 1L)
.getResultList();
assertNotNull(results);
} );
}
}

View File

@ -1,122 +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.query.hhh13712;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Tuple;
import java.util.List;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@TestForIssue(jiraKey = "HHH-13712")
public class HHH13712Test extends BaseCoreFunctionalTestCase {
@Before
public void setUp() {
doInJPA(this::sessionFactory, em -> {
SomeOther a_1 = new SomeOther(1L);
SomeOther a_2 = new SomeOther(2L);
SomeOther a_3 = new SomeOther(3L);
SubObject b_5 = new SubObject(5L, a_1);
SubObject b_6 = new SubObject(6L, a_2);
SubObject b_7 = new SubObject(7L, a_3);
em.merge(a_1);
em.merge(a_2);
em.merge(a_3);
em.merge(b_5);
em.merge(b_6);
em.merge(b_7);
});
}
@Test
public void testJoinSuperclassAssociationOnly() {
doInJPA(this::sessionFactory, em -> {
List<Integer> actual = em.createQuery("SELECT 1 FROM SubObject sub LEFT JOIN sub.parent p", Integer.class).getResultList();
assertEquals(3, actual.size());
});
}
@Test
public void testJoinSuperclassAssociation() {
doInJPA(this::sessionFactory, em -> {
long actual = em.createQuery("SELECT COUNT(sub) FROM SubObject sub LEFT JOIN sub.parent p WHERE p.id = 1", Long.class).getSingleResult();
assertEquals(1L, actual);
});
}
@Test
public void testCountParentIds() {
doInJPA(this::sessionFactory, em -> {
long actual = em.createQuery("SELECT COUNT(distinct sub.parent.id) FROM SubObject sub", Long.class).getSingleResult();
assertEquals(3L, actual);
});
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Super.class, SubObject.class, SomeOther.class };
}
@Entity(name = "Super")
@Inheritance(strategy = InheritanceType.JOINED)
public static class Super {
@Id
@Column
Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false)
SomeOther parent;
}
@Entity(name = "SubObject")
public static class SubObject extends Super {
SubObject() {}
SubObject(Long id, SomeOther parent) {
this.id = id;
this.parent = parent;
}
}
@Entity(name = "SomeOther")
public static class SomeOther {
@Id
@Column
Long id;
SomeOther() {}
SomeOther(Long id) {
this.id = id;
}
}
}

View File

@ -2,7 +2,7 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.query.hhh12225"> <hibernate-mapping package="org.hibernate.orm.test.query.hhh12225">
<class name="Contract" table="contract" > <class name="Contract" table="contract" >
<meta attribute="class-description"> <meta attribute="class-description">
@ -33,7 +33,7 @@
<meta attribute="validate:min-size">1</meta> <meta attribute="validate:min-size">1</meta>
<meta attribute="validate:max-size">1</meta> <meta attribute="validate:max-size">1</meta>
<key column="contract_id" /> <key column="contract_id" />
<one-to-many class="org.hibernate.query.hhh12225.Vehicle" /> <one-to-many class="org.hibernate.orm.test.query.hhh12225.Vehicle" />
</bag> </bag>
<joined-subclass name="VehicleTrackContract" table="contract_vehicle_track"> <joined-subclass name="VehicleTrackContract" table="contract_vehicle_track">
<key column="contract_id" /> <key column="contract_id" />

View File

@ -2,7 +2,7 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.query.hhh12225"> <hibernate-mapping package="org.hibernate.orm.test.query.hhh12225">
<class name="Vehicle"> <class name="Vehicle">
<meta attribute="class-description"> <meta attribute="class-description">

View File

@ -9,7 +9,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.query.hhh12076.Claim" name="org.hibernate.orm.test.query.hhh12076.Claim"
table="claim" table="claim"
lazy="false"> lazy="false">
@ -68,7 +68,7 @@
<key> <key>
<column name="claim_id" not-null="true"/> <column name="claim_id" not-null="true"/>
</key> </key>
<one-to-many class="org.hibernate.query.hhh12076.Extension"/> <one-to-many class="org.hibernate.orm.test.query.hhh12076.Extension"/>
</set> </set>
<set <set
name="settlements" name="settlements"
@ -80,7 +80,7 @@
<key> <key>
<column name="claim_id" not-null="true"/> <column name="claim_id" not-null="true"/>
</key> </key>
<one-to-many class="org.hibernate.query.hhh12076.Settlement"/> <one-to-many class="org.hibernate.orm.test.query.hhh12076.Settlement"/>
</set> </set>
</class> </class>
</hibernate-mapping> </hibernate-mapping>

View File

@ -9,8 +9,8 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<joined-subclass <joined-subclass
name="org.hibernate.query.hhh12076.EwtAssessmentExtension" name="org.hibernate.orm.test.query.hhh12076.EwtAssessmentExtension"
extends="org.hibernate.query.hhh12076.SettlementExtension" extends="org.hibernate.orm.test.query.hhh12076.SettlementExtension"
table="claim_settlement_ext_i3_ewt" table="claim_settlement_ext_i3_ewt"
lazy="false"> lazy="false">

View File

@ -9,7 +9,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.query.hhh12076.Extension" name="org.hibernate.orm.test.query.hhh12076.Extension"
table="claim_ext" table="claim_ext"
lazy="false"> lazy="false">
@ -29,7 +29,7 @@
<column name="type" length="128" not-null="true"/> <column name="type" length="128" not-null="true"/>
</property> </property>
<many-to-one name="claim" class="org.hibernate.query.hhh12076.Claim" fetch="select"> <many-to-one name="claim" class="org.hibernate.orm.test.query.hhh12076.Claim" fetch="select">
<column name="claim_id" not-null="true"/> <column name="claim_id" not-null="true"/>
</many-to-one> </many-to-one>
</class> </class>

View File

@ -9,8 +9,8 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<joined-subclass <joined-subclass
name="org.hibernate.query.hhh12076.GapAssessmentExtension" name="org.hibernate.orm.test.query.hhh12076.GapAssessmentExtension"
extends="org.hibernate.query.hhh12076.SettlementExtension" extends="org.hibernate.orm.test.query.hhh12076.SettlementExtension"
table="claim_settlement_ext_gap" table="claim_settlement_ext_gap"
lazy="false"> lazy="false">

View File

@ -9,7 +9,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.query.hhh12076.Settlement" name="org.hibernate.orm.test.query.hhh12076.Settlement"
table="claim_settlement" table="claim_settlement"
lazy="false"> lazy="false">
@ -38,13 +38,13 @@
<column name="status" not-null="true"/> <column name="status" not-null="true"/>
<type name="org.hibernate.type.EnumType"> <type name="org.hibernate.type.EnumType">
<param name="type">12</param> <param name="type">12</param>
<param name="enumClass">org.hibernate.query.hhh12076.SettlementStatus</param> <param name="enumClass">org.hibernate.orm.test.query.hhh12076.SettlementStatus</param>
</type> </type>
</property> </property>
<many-to-one <many-to-one
name="claim" name="claim"
class="org.hibernate.query.hhh12076.Claim" class="org.hibernate.orm.test.query.hhh12076.Claim"
fetch="select"> fetch="select">
<column name="claim_id" not-null="true"/> <column name="claim_id" not-null="true"/>
</many-to-one> </many-to-one>
@ -57,7 +57,7 @@
batch-size="10" batch-size="10"
order-by="order_index"> order-by="order_index">
<key column="settlement_id" not-null="true"/> <key column="settlement_id" not-null="true"/>
<one-to-many class="org.hibernate.query.hhh12076.SettlementExtension"/> <one-to-many class="org.hibernate.orm.test.query.hhh12076.SettlementExtension"/>
</set> </set>
</class> </class>

View File

@ -9,7 +9,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.query.hhh12076.SettlementExtension" name="org.hibernate.orm.test.query.hhh12076.SettlementExtension"
table="claim_settlement_ext" table="claim_settlement_ext"
abstract="true" abstract="true"
lazy="false"> lazy="false">
@ -31,7 +31,7 @@
<many-to-one <many-to-one
name="settlement" name="settlement"
class="org.hibernate.query.hhh12076.Settlement" class="org.hibernate.orm.test.query.hhh12076.Settlement"
fetch="select"> fetch="select">
<column name="settlement_id" not-null="true"/> <column name="settlement_id" not-null="true"/>
</many-to-one> </many-to-one>

View File

@ -9,14 +9,14 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<subclass <subclass
name="org.hibernate.query.hhh12076.SettlementTask" name="org.hibernate.orm.test.query.hhh12076.SettlementTask"
extends="org.hibernate.query.hhh12076.Task" extends="org.hibernate.orm.test.query.hhh12076.Task"
discriminator-value="org.hibernate.query.hhh12076.SettlementTask" discriminator-value="org.hibernate.orm.test.query.hhh12076.SettlementTask"
lazy="false"> lazy="false">
<many-to-one <many-to-one
name="linked" name="linked"
class="org.hibernate.query.hhh12076.Settlement" class="org.hibernate.orm.test.query.hhh12076.Settlement"
fetch="join"> fetch="join">
<column name="linked_id" not-null="true"/> <column name="linked_id" not-null="true"/>
</many-to-one> </many-to-one>

View File

@ -9,7 +9,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.query.hhh12076.Task" name="org.hibernate.orm.test.query.hhh12076.Task"
abstract="true" abstract="true"
table="wf_task" table="wf_task"
lazy="false"> lazy="false">
@ -54,13 +54,13 @@
</property> </property>
<many-to-one <many-to-one
name="status" name="status"
class="org.hibernate.query.hhh12076.TaskStatus" class="org.hibernate.orm.test.query.hhh12076.TaskStatus"
fetch="select"> fetch="select">
<column name="task_status" not-null="true"/> <column name="task_status" not-null="true"/>
</many-to-one> </many-to-one>
<many-to-one <many-to-one
name="parent" name="parent"
class="org.hibernate.query.hhh12076.Task" class="org.hibernate.orm.test.query.hhh12076.Task"
fetch="select"> fetch="select">
<column name="parent_id" not-null="false"/> <column name="parent_id" not-null="false"/>
</many-to-one> </many-to-one>
@ -72,7 +72,7 @@
cascade="all,delete-orphan" cascade="all,delete-orphan"
batch-size="10"> batch-size="10">
<key column="parent_id"/> <key column="parent_id"/>
<one-to-many class="org.hibernate.query.hhh12076.Task"/> <one-to-many class="org.hibernate.orm.test.query.hhh12076.Task"/>
</set> </set>
<set <set
name="linkedTasks" name="linkedTasks"
@ -83,7 +83,7 @@
cascade="none"> cascade="none">
<key column="task_id"/> <key column="task_id"/>
<many-to-many <many-to-many
class="org.hibernate.query.hhh12076.Task" class="org.hibernate.orm.test.query.hhh12076.Task"
column="link_to_task_id" column="link_to_task_id"
/> />
</set> </set>

View File

@ -9,7 +9,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <hibernate-mapping>
<class <class
name="org.hibernate.query.hhh12076.TaskStatus" name="org.hibernate.orm.test.query.hhh12076.TaskStatus"
table="wf_task_status" table="wf_task_status"
lazy="false"> lazy="false">