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