Fix MappingModelCreationHelper#interpretToOneKeyDescriptor() throwing NotYetImplementedFor6Exception for NonAggregateIdentifier
This commit is contained in:
parent
d33200b309
commit
55b1ec48f1
|
@ -1063,6 +1063,10 @@ public class MappingModelCreationHelper {
|
||||||
);
|
);
|
||||||
attributeMapping.setForeignKeyDescriptor( embeddedForeignKeyDescriptor );
|
attributeMapping.setForeignKeyDescriptor( embeddedForeignKeyDescriptor );
|
||||||
}
|
}
|
||||||
|
else if ( modelPart == null ) {
|
||||||
|
throw new IllegalArgumentException( "Unable to find attribute " + bootProperty.getPersistentClass()
|
||||||
|
.getEntityName() + " -> " + bootProperty.getName() );
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new NotYetImplementedFor6Exception(
|
throw new NotYetImplementedFor6Exception(
|
||||||
"Support for foreign-keys based on `" + modelPart + "` not yet implemented: " +
|
"Support for foreign-keys based on `" + modelPart + "` not yet implemented: " +
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
import org.hibernate.orm.test.util.SchemaUtil;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
@DomainModel(
|
||||||
|
annotatedClasses = {
|
||||||
|
Dependent.class,
|
||||||
|
Employee.class
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class DerivedIdentityWithBidirectionalAssociationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBidirectionalAssociation(SessionFactoryScope scope) {
|
||||||
|
final MetadataImplementor metadata = scope.getMetadataImplementor();
|
||||||
|
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata ) );
|
||||||
|
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata ) );
|
||||||
|
|
||||||
|
Employee e = new Employee();
|
||||||
|
e.empId = 1;
|
||||||
|
e.empName = "Emmanuel";
|
||||||
|
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
session.persist( e );
|
||||||
|
Dependent d = new Dependent();
|
||||||
|
d.emp = e;
|
||||||
|
session.persist( d );
|
||||||
|
session.flush();
|
||||||
|
session.clear();
|
||||||
|
d = getDerivedClassById( e, session, Dependent.class );
|
||||||
|
assertEquals( e.empId, d.emp.empId );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T getDerivedClassById(Employee e, Session s, Class<T> clazz) {
|
||||||
|
return clazz.cast( s.createQuery( "from " + clazz.getName() + " d where d.emp.empId = :empId" )
|
||||||
|
.setParameter( "empId", e.empId ).uniqueResult() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import jakarta.persistence.CascadeType;
|
import jakarta.persistence.CascadeType;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
|
@ -4,9 +4,21 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import jakarta.persistence.CascadeType;
|
import jakarta.persistence.CascadeType;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
|
@ -15,27 +27,23 @@ import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
|
|
||||||
import org.hibernate.annotations.Fetch;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
@DomainModel(
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
annotatedClasses = {
|
||||||
import org.junit.After;
|
OneToOneLazyDerivedIdFetchModeSelectTest.Foo.class,
|
||||||
import org.junit.Before;
|
OneToOneLazyDerivedIdFetchModeSelectTest.Bar.class,
|
||||||
import org.junit.Test;
|
}
|
||||||
|
)
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
@SessionFactory
|
||||||
import static org.junit.Assert.assertEquals;
|
public class OneToOneLazyDerivedIdFetchModeSelectTest {
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
public class OneToOneLazyDerivedIdFetchModeSelectTest extends BaseCoreFunctionalTestCase {
|
|
||||||
private Foo foo;
|
private Foo foo;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-14390")
|
@TestForIssue(jiraKey = "HHH-14390")
|
||||||
public void testQuery() {
|
public void testQuery(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
|
||||||
Bar newBar = (Bar) session.createQuery( "SELECT b FROM Bar b WHERE b.foo.id = :id" )
|
Bar newBar = (Bar) session.createQuery( "SELECT b FROM Bar b WHERE b.foo.id = :id" )
|
||||||
.setParameter( "id", foo.getId() )
|
.setParameter( "id", foo.getId() )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
|
@ -48,9 +56,8 @@ public class OneToOneLazyDerivedIdFetchModeSelectTest extends BaseCoreFunctional
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-14390")
|
@TestForIssue(jiraKey = "HHH-14390")
|
||||||
public void testQueryById() {
|
public void testQueryById(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
|
||||||
Bar newBar = (Bar) session.createQuery( "SELECT b FROM Bar b WHERE b.foo = :foo" )
|
Bar newBar = (Bar) session.createQuery( "SELECT b FROM Bar b WHERE b.foo = :foo" )
|
||||||
.setParameter( "foo", foo )
|
.setParameter( "foo", foo )
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
|
@ -63,9 +70,8 @@ public class OneToOneLazyDerivedIdFetchModeSelectTest extends BaseCoreFunctional
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-14390")
|
@TestForIssue(jiraKey = "HHH-14390")
|
||||||
public void testFindByPrimaryKey() {
|
public void testFindByPrimaryKey(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
|
||||||
Bar newBar = session.find( Bar.class, foo.getId() );
|
Bar newBar = session.find( Bar.class, foo.getId() );
|
||||||
assertNotNull( newBar );
|
assertNotNull( newBar );
|
||||||
assertNotNull( newBar.getFoo() );
|
assertNotNull( newBar.getFoo() );
|
||||||
|
@ -74,9 +80,9 @@ public class OneToOneLazyDerivedIdFetchModeSelectTest extends BaseCoreFunctional
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setupData() {
|
public void setupData(SessionFactoryScope scope) {
|
||||||
this.foo = doInHibernate( this::sessionFactory, session -> {
|
this.foo = scope.fromTransaction( session -> {
|
||||||
Foo foo = new Foo();
|
Foo foo = new Foo();
|
||||||
session.persist( foo );
|
session.persist( foo );
|
||||||
|
|
||||||
|
@ -97,23 +103,15 @@ public class OneToOneLazyDerivedIdFetchModeSelectTest extends BaseCoreFunctional
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void cleanupData() {
|
public void cleanupData(SessionFactoryScope scope) {
|
||||||
this.foo = null;
|
this.foo = null;
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
scope.inTransaction( session -> {
|
||||||
session.createQuery( "delete from Bar" );
|
session.createQuery( "delete from Bar" );
|
||||||
session.createQuery( "delete from Foo" );
|
session.createQuery( "delete from Foo" );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[] {
|
|
||||||
Foo.class,
|
|
||||||
Bar.class,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity(name = "Foo")
|
@Entity(name = "Foo")
|
||||||
public static class Foo implements Serializable {
|
public static class Foo implements Serializable {
|
||||||
|
|
|
@ -0,0 +1,257 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.query.Query;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@DomainModel(
|
||||||
|
annotatedClasses = {
|
||||||
|
Foo.class,
|
||||||
|
Bar.class,
|
||||||
|
Person.class,
|
||||||
|
PersonInfo.class
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class OneToOneWithDerivedIdentityTest {
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
session.createQuery( "delete from Bar" ).executeUpdate();
|
||||||
|
session.createQuery( "delete from Foo" ).executeUpdate();
|
||||||
|
session.createQuery( "delete from PersonInfo" ).executeUpdate();
|
||||||
|
session.createQuery( "delete from Person" ).executeUpdate();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-11903")
|
||||||
|
public void testInsertFooAndBarWithDerivedId(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setDetails( "Some details" );
|
||||||
|
Foo foo = new Foo();
|
||||||
|
foo.setBar( bar );
|
||||||
|
bar.setFoo( foo );
|
||||||
|
session.persist( foo );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
assertNotNull( foo.getId() );
|
||||||
|
assertEquals( foo.getId(), bar.getFoo().getId() );
|
||||||
|
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
Bar newBar = (Bar) session.createQuery( "SELECT b FROM Bar b WHERE b.foo.id = :id" )
|
||||||
|
.setParameter( "id", foo.getId() )
|
||||||
|
.uniqueResult();
|
||||||
|
|
||||||
|
assertNotNull( newBar );
|
||||||
|
assertNotNull( newBar.getFoo() );
|
||||||
|
assertEquals( foo.getId(), newBar.getFoo().getId() );
|
||||||
|
assertEquals( "Some details", newBar.getDetails() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14389")
|
||||||
|
public void testQueryById(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setDetails( "Some details" );
|
||||||
|
Foo foo = new Foo();
|
||||||
|
foo.setBar( bar );
|
||||||
|
bar.setFoo( foo );
|
||||||
|
session.persist( foo );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
assertNotNull( foo.getId() );
|
||||||
|
assertEquals( foo.getId(), bar.getFoo().getId() );
|
||||||
|
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
Bar newBar = (Bar) session.createQuery( "SELECT b FROM Bar b WHERE b.foo = :foo" )
|
||||||
|
.setParameter( "foo", foo )
|
||||||
|
.uniqueResult();
|
||||||
|
|
||||||
|
assertNotNull( newBar );
|
||||||
|
assertNotNull( newBar.getFoo() );
|
||||||
|
assertEquals( foo.getId(), newBar.getFoo().getId() );
|
||||||
|
assertEquals( "Some details", newBar.getDetails() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14389")
|
||||||
|
public void testFindById(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setDetails( "Some details" );
|
||||||
|
Foo foo = new Foo();
|
||||||
|
foo.setBar( bar );
|
||||||
|
bar.setFoo( foo );
|
||||||
|
session.persist( foo );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
assertNotNull( foo.getId() );
|
||||||
|
assertEquals( foo.getId(), bar.getFoo().getId() );
|
||||||
|
|
||||||
|
session.clear();
|
||||||
|
try {
|
||||||
|
session.find( Bar.class, foo );
|
||||||
|
fail( "Should have thrown IllegalArgumentException" );
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14389")
|
||||||
|
public void testFindByPrimaryKey(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setDetails( "Some details" );
|
||||||
|
Foo foo = new Foo();
|
||||||
|
foo.setBar( bar );
|
||||||
|
bar.setFoo( foo );
|
||||||
|
session.persist( foo );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
assertNotNull( foo.getId() );
|
||||||
|
assertEquals( foo.getId(), bar.getFoo().getId() );
|
||||||
|
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
Bar newBar = session.find( Bar.class, foo.getId() );
|
||||||
|
|
||||||
|
assertNotNull( newBar );
|
||||||
|
assertNotNull( newBar.getFoo() );
|
||||||
|
assertEquals( foo.getId(), newBar.getFoo().getId() );
|
||||||
|
assertEquals( "Some details", newBar.getDetails() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-10476")
|
||||||
|
public void testInsertFooAndBarWithDerivedIdPC(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setDetails( "Some details" );
|
||||||
|
Foo foo = new Foo();
|
||||||
|
foo.setBar( bar );
|
||||||
|
bar.setFoo( foo );
|
||||||
|
session.persist( foo );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
assertNotNull( foo.getId() );
|
||||||
|
assertEquals( foo.getId(), bar.getFoo().getId() );
|
||||||
|
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
Bar barWithFoo = new Bar();
|
||||||
|
barWithFoo.setFoo( foo );
|
||||||
|
barWithFoo.setDetails( "wrong details" );
|
||||||
|
bar = session.get( Bar.class, barWithFoo );
|
||||||
|
|
||||||
|
assertSame( bar, barWithFoo );
|
||||||
|
assertEquals( "Some details", bar.getDetails() );
|
||||||
|
assertTrue( session.getPersistenceContext().isEntryFor( bar ) );
|
||||||
|
assertFalse( session.getPersistenceContext().isEntryFor( bar.getFoo() ) );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-6813")
|
||||||
|
public void testSelectWithDerivedId(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setDetails( "Some details" );
|
||||||
|
Foo foo = new Foo();
|
||||||
|
foo.setBar( bar );
|
||||||
|
bar.setFoo( foo );
|
||||||
|
session.persist( foo );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
assertNotNull( foo.getId() );
|
||||||
|
assertEquals( foo.getId(), bar.getFoo().getId() );
|
||||||
|
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
Foo newFoo = (Foo) session.createQuery( "SELECT f FROM Foo f" ).uniqueResult();
|
||||||
|
|
||||||
|
assertNotNull( newFoo );
|
||||||
|
assertNotNull( newFoo.getBar() );
|
||||||
|
assertSame( newFoo, newFoo.getBar().getFoo() );
|
||||||
|
assertEquals( "Some details", newFoo.getBar().getDetails() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-6813")
|
||||||
|
// Regression test utilizing multiple types of queries.
|
||||||
|
public void testCase(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
Person p = new Person();
|
||||||
|
p.setName( "Alfio" );
|
||||||
|
PersonInfo pi = new PersonInfo();
|
||||||
|
pi.setId( p );
|
||||||
|
pi.setInfo( "Some information" );
|
||||||
|
session.persist( p );
|
||||||
|
session.persist( pi );
|
||||||
|
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
|
Query q = session.getNamedQuery( "PersonQuery" );
|
||||||
|
List<Person> persons = q.list();
|
||||||
|
assertEquals( persons.size(), 1 );
|
||||||
|
assertEquals( persons.get( 0 ).getName(), "Alfio" );
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.clear();
|
||||||
|
|
||||||
|
session.getTransaction().begin();
|
||||||
|
|
||||||
|
p = session.get( Person.class, persons.get( 0 ).getId() );
|
||||||
|
assertEquals( p.getName(), "Alfio" );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import jakarta.persistence.Basic;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.NamedQuery;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@NamedQuery(name = "PersonQuery", query = "SELECT p FROM Person p")
|
||||||
|
public class Person implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@OneToOne(mappedBy = "id")
|
||||||
|
private PersonInfo personInfo;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 0;
|
||||||
|
hash += ( this.id != null ? this.id.hashCode() : 0 );
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if ( !( object instanceof Person ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Person other = (Person) object;
|
||||||
|
|
||||||
|
return ( ( this.id != null ) || ( other.id == null ) ) && ( ( this.id == null ) || ( this.id.equals( other.id ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "nogroup.hibertest.Person[ id=" + this.id + " ]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public PersonInfo getPersonInfo() {
|
||||||
|
return this.personInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPersonInfo(PersonInfo personInfo) {
|
||||||
|
this.personInfo = personInfo;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.annotations.derivedidentities.bidirectional;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import jakarta.persistence.Basic;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class PersonInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@OneToOne
|
||||||
|
private Person id;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
private String info;
|
||||||
|
|
||||||
|
public Person getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Person id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo() {
|
||||||
|
return this.info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfo(String info) {
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 0;
|
||||||
|
hash += ( this.id != null ? this.id.hashCode() : 0 );
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object object) {
|
||||||
|
if ( !( object instanceof PersonInfo ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PersonInfo other = (PersonInfo) object;
|
||||||
|
|
||||||
|
return ( ( this.id != null ) || ( other.id == null ) ) && ( ( this.id == null ) || ( this.id.equals( other.id ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "nogroup.hibertest.PersonInfo[ id=" + this.id + " ]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,58 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import org.hibernate.testing.Skip;
|
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
|
||||||
import org.hibernate.orm.test.util.SchemaUtil;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Hardy Ferentschik
|
|
||||||
*/
|
|
||||||
@Skip( condition = Skip.AlwaysSkip.class,message = "sdf")
|
|
||||||
public class DerivedIdentityWithBidirectionalAssociationTest extends BaseNonConfigCoreFunctionalTestCase {
|
|
||||||
@Test
|
|
||||||
public void testBidirectionalAssociation() throws Exception {
|
|
||||||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata() ) );
|
|
||||||
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata() ) );
|
|
||||||
Employee e = new Employee();
|
|
||||||
e.empId = 1;
|
|
||||||
e.empName = "Emmanuel";
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
s.persist( e );
|
|
||||||
Dependent d = new Dependent();
|
|
||||||
d.emp = e;
|
|
||||||
s.persist( d );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
d = getDerivedClassById( e, s, Dependent.class );
|
|
||||||
assertEquals( e.empId, d.emp.empId );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T getDerivedClassById(Employee e, Session s, Class<T> clazz) {
|
|
||||||
return clazz.cast( s.createQuery( "from " + clazz.getName() + " d where d.emp.empId = :empId" )
|
|
||||||
.setParameter( "empId", e.empId ).uniqueResult() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[] {
|
|
||||||
Dependent.class,
|
|
||||||
Employee.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,236 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.query.Query;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class OneToOneWithDerivedIdentityTest extends BaseCoreFunctionalTestCase {
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-11903")
|
|
||||||
public void testInsertFooAndBarWithDerivedId() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Bar bar = new Bar();
|
|
||||||
bar.setDetails( "Some details" );
|
|
||||||
Foo foo = new Foo();
|
|
||||||
foo.setBar( bar );
|
|
||||||
bar.setFoo( foo );
|
|
||||||
s.persist( foo );
|
|
||||||
s.flush();
|
|
||||||
assertNotNull( foo.getId() );
|
|
||||||
assertEquals( foo.getId(), bar.getFoo().getId() );
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
Bar newBar = ( Bar ) s.createQuery( "SELECT b FROM Bar b WHERE b.foo.id = :id" )
|
|
||||||
.setParameter( "id", foo.getId() )
|
|
||||||
.uniqueResult();
|
|
||||||
assertNotNull( newBar );
|
|
||||||
assertNotNull( newBar.getFoo() );
|
|
||||||
assertEquals( foo.getId(), newBar.getFoo().getId() );
|
|
||||||
assertEquals( "Some details", newBar.getDetails() );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-14389")
|
|
||||||
public void testQueryById() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Bar bar = new Bar();
|
|
||||||
bar.setDetails( "Some details" );
|
|
||||||
Foo foo = new Foo();
|
|
||||||
foo.setBar( bar );
|
|
||||||
bar.setFoo( foo );
|
|
||||||
s.persist( foo );
|
|
||||||
s.flush();
|
|
||||||
assertNotNull( foo.getId() );
|
|
||||||
assertEquals( foo.getId(), bar.getFoo().getId() );
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
Bar newBar = ( Bar ) s.createQuery( "SELECT b FROM Bar b WHERE b.foo = :foo" )
|
|
||||||
.setParameter( "foo", foo )
|
|
||||||
.uniqueResult();
|
|
||||||
assertNotNull( newBar );
|
|
||||||
assertNotNull( newBar.getFoo() );
|
|
||||||
assertEquals( foo.getId(), newBar.getFoo().getId() );
|
|
||||||
assertEquals( "Some details", newBar.getDetails() );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-14389")
|
|
||||||
public void testFindById() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Bar bar = new Bar();
|
|
||||||
bar.setDetails( "Some details" );
|
|
||||||
Foo foo = new Foo();
|
|
||||||
foo.setBar( bar );
|
|
||||||
bar.setFoo( foo );
|
|
||||||
s.persist( foo );
|
|
||||||
s.flush();
|
|
||||||
assertNotNull( foo.getId() );
|
|
||||||
assertEquals( foo.getId(), bar.getFoo().getId() );
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
try {
|
|
||||||
s.find( Bar.class, foo );
|
|
||||||
fail( "Should have thrown IllegalArgumentException" );
|
|
||||||
}
|
|
||||||
catch(IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-14389")
|
|
||||||
public void testFindByPrimaryKey() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Bar bar = new Bar();
|
|
||||||
bar.setDetails( "Some details" );
|
|
||||||
Foo foo = new Foo();
|
|
||||||
foo.setBar( bar );
|
|
||||||
bar.setFoo( foo );
|
|
||||||
s.persist( foo );
|
|
||||||
s.flush();
|
|
||||||
assertNotNull( foo.getId() );
|
|
||||||
assertEquals( foo.getId(), bar.getFoo().getId() );
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
Bar newBar = s.find( Bar.class, foo.getId() );
|
|
||||||
assertNotNull( newBar );
|
|
||||||
assertNotNull( newBar.getFoo() );
|
|
||||||
assertEquals( foo.getId(), newBar.getFoo().getId() );
|
|
||||||
assertEquals( "Some details", newBar.getDetails() );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue( jiraKey = "HHH-10476")
|
|
||||||
public void testInsertFooAndBarWithDerivedIdPC() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Bar bar = new Bar();
|
|
||||||
bar.setDetails( "Some details" );
|
|
||||||
Foo foo = new Foo();
|
|
||||||
foo.setBar( bar );
|
|
||||||
bar.setFoo( foo );
|
|
||||||
s.persist( foo );
|
|
||||||
s.flush();
|
|
||||||
assertNotNull( foo.getId() );
|
|
||||||
assertEquals( foo.getId(), bar.getFoo().getId() );
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
Bar barWithFoo = new Bar();
|
|
||||||
barWithFoo.setFoo( foo );
|
|
||||||
barWithFoo.setDetails( "wrong details" );
|
|
||||||
bar = (Bar) s.get( Bar.class, barWithFoo );
|
|
||||||
assertSame( bar, barWithFoo );
|
|
||||||
assertEquals( "Some details", bar.getDetails() );
|
|
||||||
SessionImplementor si = (SessionImplementor) s;
|
|
||||||
assertTrue( si.getPersistenceContext().isEntryFor( bar ) );
|
|
||||||
assertFalse( si.getPersistenceContext().isEntryFor( bar.getFoo() ) );
|
|
||||||
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-6813")
|
|
||||||
public void testSelectWithDerivedId() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Bar bar = new Bar();
|
|
||||||
bar.setDetails( "Some details" );
|
|
||||||
Foo foo = new Foo();
|
|
||||||
foo.setBar( bar );
|
|
||||||
bar.setFoo( foo );
|
|
||||||
s.persist( foo );
|
|
||||||
s.flush();
|
|
||||||
assertNotNull( foo.getId() );
|
|
||||||
assertEquals( foo.getId(), bar.getFoo().getId() );
|
|
||||||
|
|
||||||
s.clear();
|
|
||||||
Foo newFoo = (Foo) s.createQuery( "SELECT f FROM Foo f" ).uniqueResult();
|
|
||||||
assertNotNull( newFoo );
|
|
||||||
assertNotNull( newFoo.getBar() );
|
|
||||||
assertSame( newFoo, newFoo.getBar().getFoo() );
|
|
||||||
assertEquals( "Some details", newFoo.getBar().getDetails() );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-6813")
|
|
||||||
// Regression test utilizing multiple types of queries.
|
|
||||||
public void testCase() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
|
|
||||||
Person p = new Person();
|
|
||||||
p.setName( "Alfio" );
|
|
||||||
PersonInfo pi = new PersonInfo();
|
|
||||||
pi.setId( p );
|
|
||||||
pi.setInfo( "Some information" );
|
|
||||||
s.persist( p );
|
|
||||||
s.persist( pi );
|
|
||||||
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
s.getTransaction().begin();
|
|
||||||
|
|
||||||
Query q = s.getNamedQuery( "PersonQuery" );
|
|
||||||
List<Person> persons = q.list();
|
|
||||||
assertEquals( persons.size(), 1 );
|
|
||||||
assertEquals( persons.get( 0 ).getName(), "Alfio" );
|
|
||||||
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
s.getTransaction().begin();
|
|
||||||
|
|
||||||
p = (Person) s.get( Person.class, persons.get( 0 ).getId() );
|
|
||||||
assertEquals( p.getName(), "Alfio" );
|
|
||||||
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[] {
|
|
||||||
Foo.class,
|
|
||||||
Bar.class,
|
|
||||||
Person.class,
|
|
||||||
PersonInfo.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import jakarta.persistence.Basic;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.NamedQuery;
|
|
||||||
import jakarta.persistence.OneToOne;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@NamedQuery(name="PersonQuery", query="SELECT p FROM Person p")
|
|
||||||
public class Person
|
|
||||||
implements Serializable
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@Basic
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@OneToOne(mappedBy="id")
|
|
||||||
private PersonInfo personInfo;
|
|
||||||
|
|
||||||
public Integer getId()
|
|
||||||
{
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
int hash = 0;
|
|
||||||
hash += (this.id != null ? this.id.hashCode() : 0);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object object)
|
|
||||||
{
|
|
||||||
if (!(object instanceof Person)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Person other = (Person)object;
|
|
||||||
|
|
||||||
return ((this.id != null) || (other.id == null)) && ((this.id == null) || (this.id.equals(other.id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "nogroup.hibertest.Person[ id=" + this.id + " ]";
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersonInfo getPersonInfo()
|
|
||||||
{
|
|
||||||
return this.personInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPersonInfo(PersonInfo personInfo)
|
|
||||||
{
|
|
||||||
this.personInfo = personInfo;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.annotations.derivedidentities.bidirectional;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import jakarta.persistence.Basic;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.OneToOne;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class PersonInfo
|
|
||||||
implements Serializable
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@OneToOne
|
|
||||||
private Person id;
|
|
||||||
|
|
||||||
@Basic
|
|
||||||
private String info;
|
|
||||||
|
|
||||||
public Person getId()
|
|
||||||
{
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Person id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInfo() {
|
|
||||||
return this.info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInfo(String info) {
|
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
int hash = 0;
|
|
||||||
hash += (this.id != null ? this.id.hashCode() : 0);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object object)
|
|
||||||
{
|
|
||||||
if (!(object instanceof PersonInfo)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
PersonInfo other = (PersonInfo)object;
|
|
||||||
|
|
||||||
return ((this.id != null) || (other.id == null)) && ((this.id == null) || (this.id.equals(other.id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "nogroup.hibertest.PersonInfo[ id=" + this.id + " ]";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue