Fix RIGHT OUTER attribute-joins are not supported
This commit is contained in:
parent
da625e18a9
commit
09266c7ae1
|
@ -1500,10 +1500,6 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
|
|||
sqmRoot.addSqmJoin( join );
|
||||
}
|
||||
else {
|
||||
if ( joinType == SqmJoinType.RIGHT ) {
|
||||
throw new SemanticException( "RIGHT OUTER attribute-joins are not supported : " + parserJoin.getText() );
|
||||
}
|
||||
|
||||
if ( getCreationOptions().useStrictJpaCompliance() ) {
|
||||
if ( join.getExplicitAlias() != null ){
|
||||
//noinspection rawtypes
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.hibernate.test.inheritance;
|
||||
package org.hibernate.orm.test.inheritance;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
@ -14,10 +13,13 @@ import javax.persistence.UniqueConstraint;
|
|||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Vlad Paln
|
||||
|
@ -29,20 +31,15 @@ import org.junit.Test;
|
|||
comment = "This test relies on 'hibernate.hbm2ddl.halt_on_error', only tested on h2; " +
|
||||
"other dialects might be broken due to irrelevant reason (e.g. not supporting 'if exists' while dropping tables)."
|
||||
)
|
||||
public class DenormalizedTablePhysicalIncludedTableConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.HBM2DDL_HALT_ON_ERROR, Boolean.TRUE.toString() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
SuperClass.class,
|
||||
SubClass.class
|
||||
};
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DenormalizedTablePhysicalIncludedTableConstraintTest.SuperClass.class,
|
||||
DenormalizedTablePhysicalIncludedTableConstraintTest.SubClass.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(settings = @Setting( name = AvailableSettings.HBM2DDL_HALT_ON_ERROR, value = "true"))
|
||||
public class DenormalizedTablePhysicalIncludedTableConstraintTest {
|
||||
|
||||
@Test
|
||||
public void testUniqueConstraintFromSupTableNotAppliedToSubTable() {
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.inheritance;
|
||||
package org.hibernate.orm.test.inheritance;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -27,30 +27,43 @@ import javax.persistence.criteria.ParameterExpression;
|
|||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
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 static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14103")
|
||||
public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
TransientOverrideAsPersistentJoined.Employee.class,
|
||||
TransientOverrideAsPersistentJoined.Editor.class,
|
||||
TransientOverrideAsPersistentJoined.Writer.class,
|
||||
TransientOverrideAsPersistentJoined.Group.class,
|
||||
TransientOverrideAsPersistentJoined.Job.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class TransientOverrideAsPersistentJoined {
|
||||
|
||||
@Test
|
||||
public void testFindByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.find( Employee.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Employee writer = session.find( Employee.class, "John Smith" );
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertEquals( "Writing", writer.getTitle() );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
final Group group = ( (Writer) writer ).getGroup();
|
||||
|
@ -63,8 +76,8 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFindBySubclass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindBySubclass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.find( Editor.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
|
@ -81,14 +94,15 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final List<Employee> employees = session.createQuery( "from Employee", Employee.class )
|
||||
.getResultList();
|
||||
assertEquals( 2, employees.size() );
|
||||
employees.sort( Comparator.comparing( Employee::getName ) );
|
||||
assertTrue( Editor.class.isInstance( employees.get( 0 ) ) );
|
||||
assertTrue( Writer.class.isInstance( employees.get( 1 ) ) );
|
||||
assertThat( employees.get( 0 ), instanceOf( Editor.class ) );
|
||||
assertThat( employees.get( 1 ), instanceOf( Writer.class ) );
|
||||
|
||||
final Editor editor = (Editor) employees.get( 0 );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Writer writer = (Writer) employees.get( 1 );
|
||||
|
@ -101,17 +115,17 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-12981")
|
||||
public void testQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
|
@ -119,29 +133,35 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-12981")
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
final Employee editor = session.createQuery( "from Employee e where treat( e as Editor ).title=:title", Employee.class )
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery(
|
||||
"from Employee e where treat( e as Editor ).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee e where treat( e as Writer).title=:title", Employee.class )
|
||||
final Employee writer = session.createQuery(
|
||||
"from Employee e where treat( e as Writer).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBySublassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryBySublassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.createQuery( "from Editor where title=:title", Editor.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Writer writer = session.createQuery( "from Writer where title=:title", Writer.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
|
@ -153,8 +173,8 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-12981")
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
|
||||
final CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
|
||||
|
@ -170,7 +190,7 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
final Employee editor = session.createQuery( query )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Predicate predicateWriter = builder.equal(
|
||||
builder.treat( root, Writer.class ).get( "title" ),
|
||||
|
@ -180,16 +200,16 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
final Employee writer = session.createQuery( query )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupData() {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
Job jobEditor = new Job( "Edit" );
|
||||
jobEditor.setEmployee( new Editor( "Jane Smith", "Senior Editor" ) );
|
||||
Job jobWriter = new Job( "Write" );
|
||||
|
@ -207,26 +227,15 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanupData() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@AfterEach
|
||||
public void cleanupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.createQuery( "delete from Job" ).executeUpdate();
|
||||
session.createQuery( "delete from Employee" ).executeUpdate();
|
||||
session.createQuery( "delete from Group" ).executeUpdate();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Employee.class,
|
||||
Editor.class,
|
||||
Writer.class,
|
||||
Group.class,
|
||||
Job.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "Employee")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
@DiscriminatorColumn(name = "department")
|
||||
|
@ -327,6 +336,8 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
public static class Group {
|
||||
private String name;
|
||||
|
||||
private String details;
|
||||
|
||||
public Group(String name) {
|
||||
this();
|
||||
setName( name );
|
||||
|
@ -350,6 +361,7 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti
|
|||
public static class Job {
|
||||
private String name;
|
||||
private Employee employee;
|
||||
private String description;
|
||||
|
||||
public Job(String name) {
|
||||
this();
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.inheritance;
|
||||
package org.hibernate.orm.test.inheritance;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.Column;
|
||||
|
@ -28,28 +28,41 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14103")
|
||||
public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
TransientOverrideAsPersistentMappedSuperclass.Employee.class,
|
||||
TransientOverrideAsPersistentMappedSuperclass.Editor.class,
|
||||
TransientOverrideAsPersistentMappedSuperclass.Writer.class,
|
||||
TransientOverrideAsPersistentMappedSuperclass.Group.class,
|
||||
TransientOverrideAsPersistentMappedSuperclass.Job.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class TransientOverrideAsPersistentMappedSuperclass {
|
||||
|
||||
@Test
|
||||
public void testFindByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.find( Employee.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Employee writer = session.find( Employee.class, "John Smith" );
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertEquals( "Writing", writer.getTitle() );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
final Group group = ( (Writer) writer ).getGroup();
|
||||
|
@ -62,8 +75,8 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFindBySubclass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindBySubclass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.find( Editor.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
|
@ -80,13 +93,13 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final List<Employee> employees = session.createQuery( "from Employee", Employee.class )
|
||||
.getResultList();
|
||||
assertEquals( 2, employees.size() );
|
||||
assertTrue( Editor.class.isInstance( employees.get( 0 ) ) );
|
||||
assertTrue( Writer.class.isInstance( employees.get( 1 ) ) );
|
||||
assertThat( employees.get( 0 ), instanceOf( Editor.class ) );
|
||||
assertThat( employees.get( 1 ), instanceOf( Writer.class ) );
|
||||
final Editor editor = (Editor) employees.get( 0 );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Writer writer = (Writer) employees.get( 1 );
|
||||
|
@ -98,46 +111,52 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
final Employee editor = session.createQuery( "from Employee e where treat( e as Editor ).title=:title", Employee.class )
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery(
|
||||
"from Employee e where treat( e as Editor ).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee e where treat( e as Writer).title=:title", Employee.class )
|
||||
final Employee writer = session.createQuery(
|
||||
"from Employee e where treat( e as Writer).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBySublassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryBySublassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.createQuery( "from Editor where title=:title", Editor.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Writer writer = session.createQuery( "from Writer where title=:title", Writer.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
|
@ -148,8 +167,8 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
|
||||
final CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
|
||||
|
@ -165,7 +184,7 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
final Employee editor = session.createQuery( query )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Predicate predicateWriter = builder.equal(
|
||||
builder.treat( root, Writer.class ).get( "title" ),
|
||||
|
@ -175,16 +194,15 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
final Employee writer = session.createQuery( query )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupData() {
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
Job jobEditor = new Job( "Edit" );
|
||||
jobEditor.setEmployee( new Editor( "Jane Smith", "Senior Editor" ) );
|
||||
Job jobWriter = new Job( "Write" );
|
||||
|
@ -202,26 +220,15 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanupData() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@AfterEach
|
||||
public void cleanupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.createQuery( "delete from Job" ).executeUpdate();
|
||||
session.createQuery( "delete from Employee" ).executeUpdate();
|
||||
session.createQuery( "delete from Group" ).executeUpdate();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Employee.class,
|
||||
Editor.class,
|
||||
Writer.class,
|
||||
Group.class,
|
||||
Job.class
|
||||
};
|
||||
}
|
||||
|
||||
@MappedSuperclass
|
||||
public static class AbstractEmployee {
|
||||
private String title;
|
||||
|
@ -326,6 +333,8 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
public static class Group {
|
||||
private String name;
|
||||
|
||||
private String desctiption;
|
||||
|
||||
public Group(String name) {
|
||||
this();
|
||||
setName( name );
|
||||
|
@ -350,6 +359,8 @@ public class TransientOverrideAsPersistentMappedSuperclass extends BaseNonConfig
|
|||
private String name;
|
||||
private Employee employee;
|
||||
|
||||
private String description;
|
||||
|
||||
public Job(String name) {
|
||||
this();
|
||||
setName( name );
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.inheritance;
|
||||
package org.hibernate.orm.test.inheritance;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.Column;
|
||||
|
@ -26,30 +26,41 @@ import javax.persistence.criteria.ParameterExpression;
|
|||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14103")
|
||||
public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
TransientOverrideAsPersistentSingleTable.Employee.class,
|
||||
TransientOverrideAsPersistentSingleTable.Editor.class,
|
||||
TransientOverrideAsPersistentSingleTable.Writer.class,
|
||||
TransientOverrideAsPersistentSingleTable.Group.class,
|
||||
TransientOverrideAsPersistentSingleTable.Job.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class TransientOverrideAsPersistentSingleTable {
|
||||
|
||||
@Test
|
||||
public void testFindByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.find( Employee.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Employee writer = session.find( Employee.class, "John Smith" );
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertEquals( "Writing", writer.getTitle() );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
final Group group = ( (Writer) writer ).getGroup();
|
||||
|
@ -62,8 +73,8 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFindBySubclass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindBySubclass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.find( Editor.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
|
@ -80,13 +91,13 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final List<Employee> employees = session.createQuery( "from Employee", Employee.class )
|
||||
.getResultList();
|
||||
assertEquals( 2, employees.size() );
|
||||
assertTrue( Editor.class.isInstance( employees.get( 0 ) ) );
|
||||
assertTrue( Writer.class.isInstance( employees.get( 1 ) ) );
|
||||
assertThat( employees.get( 0 ), instanceOf( Editor.class ) );
|
||||
assertThat( employees.get( 1 ), instanceOf( Writer.class ) );
|
||||
final Editor editor = (Editor) employees.get( 0 );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Writer writer = (Writer) employees.get( 1 );
|
||||
|
@ -98,46 +109,52 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
final Employee editor = session.createQuery( "from Employee e where treat( e as Editor ).title=:title", Employee.class )
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery(
|
||||
"from Employee e where treat( e as Editor ).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee e where treat( e as Writer).title=:title", Employee.class )
|
||||
final Employee writer = session.createQuery(
|
||||
"from Employee e where treat( e as Writer).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBySublassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryBySublassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.createQuery( "from Editor where title=:title", Editor.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Writer writer = session.createQuery( "from Writer where title=:title", Writer.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
|
@ -148,9 +165,8 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
|
||||
final CriteriaQuery<Employee> query = builder.createQuery( Employee.class );
|
||||
|
@ -165,7 +181,7 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
final Employee editor = session.createQuery( query )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Predicate predicateWriter = builder.equal(
|
||||
builder.treat( root, Writer.class ).get( "title" ),
|
||||
|
@ -175,16 +191,15 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
final Employee writer = session.createQuery( query )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupData() {
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
Job jobEditor = new Job( "Edit" );
|
||||
jobEditor.setEmployee( new Editor( "Jane Smith", "Senior Editor" ) );
|
||||
Job jobWriter = new Job( "Write" );
|
||||
|
@ -202,26 +217,15 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanupData() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@AfterEach
|
||||
public void cleanupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.createQuery( "delete from Job" ).executeUpdate();
|
||||
session.createQuery( "delete from Employee" ).executeUpdate();
|
||||
session.createQuery( "delete from Group" ).executeUpdate();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Employee.class,
|
||||
Editor.class,
|
||||
Writer.class,
|
||||
Group.class,
|
||||
Job.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "Employee")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "department")
|
||||
|
@ -321,6 +325,7 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
@Table(name = "WorkGroup")
|
||||
public static class Group {
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public Group(String name) {
|
||||
this();
|
||||
|
@ -345,6 +350,7 @@ public class TransientOverrideAsPersistentSingleTable extends BaseNonConfigCoreF
|
|||
public static class Job {
|
||||
private String name;
|
||||
private Employee employee;
|
||||
private String description;
|
||||
|
||||
public Job(String name) {
|
||||
this();
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.inheritance;
|
||||
package org.hibernate.orm.test.inheritance;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -28,28 +28,40 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14103")
|
||||
public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
TransientOverrideAsPersistentTablePerClass.Employee.class,
|
||||
TransientOverrideAsPersistentTablePerClass.Editor.class,
|
||||
TransientOverrideAsPersistentTablePerClass.Writer.class,
|
||||
TransientOverrideAsPersistentTablePerClass.Group.class,
|
||||
TransientOverrideAsPersistentTablePerClass.Job.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class TransientOverrideAsPersistentTablePerClass {
|
||||
|
||||
@Test
|
||||
public void testFindByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.find( Employee.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Employee writer = session.find( Employee.class, "John Smith" );
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertEquals( "Writing", writer.getTitle() );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
final Group group = ( (Writer) writer ).getGroup();
|
||||
|
@ -62,8 +74,8 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFindBySubclass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testFindBySubclass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.find( Editor.class, "Jane Smith" );
|
||||
assertNotNull( editor );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
|
@ -80,14 +92,14 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClass() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final List<Employee> employees = session.createQuery( "from Employee", Employee.class )
|
||||
.getResultList();
|
||||
assertEquals( 2, employees.size() );
|
||||
employees.sort( Comparator.comparing( Employee::getName ) );
|
||||
assertTrue( Editor.class.isInstance( employees.get( 0 ) ) );
|
||||
assertTrue( Writer.class.isInstance( employees.get( 1 ) ) );
|
||||
assertThat( employees.get( 0 ), instanceOf( Editor.class ) );
|
||||
assertThat( employees.get( 1 ), instanceOf( Writer.class ) );
|
||||
final Editor editor = (Editor) employees.get( 0 );
|
||||
assertEquals( "Senior Editor", editor.getTitle() );
|
||||
final Writer writer = (Writer) employees.get( 1 );
|
||||
|
@ -99,46 +111,52 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee where title=:title", Employee.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
final Employee editor = session.createQuery( "from Employee e where treat( e as Editor ).title=:title", Employee.class )
|
||||
public void testQueryByRootClassAndOverridenPropertyTreat(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Employee editor = session.createQuery(
|
||||
"from Employee e where treat( e as Editor ).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Employee writer = session.createQuery( "from Employee e where treat( e as Writer).title=:title", Employee.class )
|
||||
final Employee writer = session.createQuery(
|
||||
"from Employee e where treat( e as Writer).title=:title",
|
||||
Employee.class
|
||||
)
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBySublassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testQueryBySublassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final Editor editor = session.createQuery( "from Editor where title=:title", Editor.class )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Writer writer = session.createQuery( "from Writer where title=:title", Writer.class )
|
||||
.setParameter( "title", "Writing" )
|
||||
|
@ -149,8 +167,8 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void testCriteriaQueryByRootClassAndOverridenProperty(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
|
||||
final CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
|
||||
|
@ -166,7 +184,7 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
final Employee editor = session.createQuery( query )
|
||||
.setParameter( "title", "Senior Editor" )
|
||||
.getSingleResult();
|
||||
assertTrue( Editor.class.isInstance( editor ) );
|
||||
assertThat( editor, instanceOf( Editor.class ) );
|
||||
|
||||
final Predicate predicateWriter = builder.equal(
|
||||
builder.treat( root, Writer.class ).get( "title" ),
|
||||
|
@ -176,16 +194,15 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
final Employee writer = session.createQuery( query )
|
||||
.setParameter( "title", "Writing" )
|
||||
.getSingleResult();
|
||||
assertTrue( Writer.class.isInstance( writer ) );
|
||||
assertThat( writer, instanceOf( Writer.class ) );
|
||||
assertNotNull( ( (Writer) writer ).getGroup() );
|
||||
assertEquals( writer.getTitle(), ( (Writer) writer ).getGroup().getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupData() {
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
Job jobEditor = new Job( "Edit" );
|
||||
jobEditor.setEmployee( new Editor( "Jane Smith", "Senior Editor" ) );
|
||||
Job jobWriter = new Job( "Write" );
|
||||
|
@ -203,26 +220,15 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanupData() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@AfterEach
|
||||
public void cleanupData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.createQuery( "delete from Job" ).executeUpdate();
|
||||
session.createQuery( "delete from Employee" ).executeUpdate();
|
||||
session.createQuery( "delete from Group" ).executeUpdate();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Employee.class,
|
||||
Editor.class,
|
||||
Writer.class,
|
||||
Group.class,
|
||||
Job.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "Employee")
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
@DiscriminatorColumn(name = "department")
|
||||
|
@ -322,6 +328,7 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
@Table(name = "WorkGroup")
|
||||
public static class Group {
|
||||
private String name;
|
||||
private String details;
|
||||
|
||||
public Group(String name) {
|
||||
this();
|
||||
|
@ -346,6 +353,7 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor
|
|||
public static class Job {
|
||||
private String name;
|
||||
private Employee employee;
|
||||
private String details;
|
||||
|
||||
public Job(String name) {
|
||||
this();
|
|
@ -120,20 +120,44 @@ public class OuterJoinTest extends BaseCoreFunctionalTestCase {
|
|||
em.merge(association);
|
||||
|
||||
em.merge(new A(1L, "a", association));
|
||||
em.merge(new A(2L, "b", association));
|
||||
em.merge(new A(3L, "c", association));
|
||||
// em.merge(new A(2L, "b", association));
|
||||
// em.merge(new A(3L, "c", association));
|
||||
//
|
||||
// em.merge(new B(1L, "d", association));
|
||||
// em.merge(new B(2L, "e", association));
|
||||
// em.merge(new B(3L, "f", association));
|
||||
//
|
||||
// em.merge(new C(1L, "g", association));
|
||||
// em.merge(new C(2L, "h", association));
|
||||
// em.merge(new C(4L, "j", association));
|
||||
//
|
||||
// em.merge(new D(1L, "k", association));
|
||||
// em.merge(new D(2L, "l", association));
|
||||
// em.merge(new D(4L, "m", association));
|
||||
});
|
||||
}
|
||||
|
||||
em.merge(new B(1L, "d", association));
|
||||
em.merge(new B(2L, "e", association));
|
||||
em.merge(new B(3L, "f", association));
|
||||
@Test
|
||||
public void mergeIt(){
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
Association association = new Association(1l, "association");
|
||||
em.merge(association);
|
||||
|
||||
em.merge(new C(1L, "g", association));
|
||||
em.merge(new C(2L, "h", association));
|
||||
em.merge(new C(4L, "j", association));
|
||||
|
||||
em.merge(new D(1L, "k", association));
|
||||
em.merge(new D(2L, "l", association));
|
||||
em.merge(new D(4L, "m", association));
|
||||
em.merge(new A(1L, "a", association));
|
||||
// em.merge(new A(2L, "b", association));
|
||||
// em.merge(new A(3L, "c", association));
|
||||
//
|
||||
// em.merge(new B(1L, "d", association));
|
||||
// em.merge(new B(2L, "e", association));
|
||||
// em.merge(new B(3L, "f", association));
|
||||
//
|
||||
// em.merge(new C(1L, "g", association));
|
||||
// em.merge(new C(2L, "h", association));
|
||||
// em.merge(new C(4L, "j", association));
|
||||
//
|
||||
// em.merge(new D(1L, "k", association));
|
||||
// em.merge(new D(2L, "l", association));
|
||||
// em.merge(new D(4L, "m", association));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -44,4 +44,11 @@ public @interface RequiresDialect {
|
|||
* the Dialect version
|
||||
*/
|
||||
int version() default -1;
|
||||
|
||||
/**
|
||||
* Comment describing the reason why the dialect is required.
|
||||
*
|
||||
* @return The comment
|
||||
*/
|
||||
String comment() default "";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue