Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-5764 - Support for multi-level derived ids
(cherry picked from commit a32372d)
- Loading branch information
Showing
16 changed files
with
484 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/b2/Dependent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.hibernate.test.annotations.derivedidentities.e3.b2; | ||
|
||
import javax.persistence.EmbeddedId; | ||
import javax.persistence.Entity; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.MapsId; | ||
|
||
@Entity | ||
public class Dependent { | ||
|
||
@EmbeddedId | ||
DependentId id; | ||
|
||
@MapsId("empPK") | ||
@ManyToOne | ||
Employee emp; | ||
} |
10 changes: 10 additions & 0 deletions
10
...ore/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/b2/DependentId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hibernate.test.annotations.derivedidentities.e3.b2; | ||
|
||
import javax.persistence.Embeddable; | ||
import java.io.Serializable; | ||
|
||
@Embeddable | ||
public class DependentId implements Serializable { | ||
String name; | ||
EmployeeId empPK; | ||
} |
87 changes: 87 additions & 0 deletions
87
...entities/e3/b2/DerivedIdentityEmbeddedIdParentEmbeddedIdGrandparentEmbeddedIdDepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as | ||
* indicated by the @author tags or express copyright attribution | ||
* statements applied by the authors. All third-party contributions are | ||
* distributed under license by Red Hat Inc. | ||
* | ||
* This copyrighted material is made available to anyone wishing to use, modify, | ||
* copy, or redistribute it subject to the terms and conditions of the GNU | ||
* Lesser General Public License, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this distribution; if not, write to: | ||
* Free Software Foundation, Inc. | ||
* 51 Franklin Street, Fifth Floor | ||
* Boston, MA 02110-1301 USA | ||
*/ | ||
package org.hibernate.test.annotations.derivedidentities.e3.b2; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.test.util.SchemaUtil; | ||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Emmanuel Bernard | ||
* @author Matt Drees | ||
*/ | ||
public class DerivedIdentityEmbeddedIdParentEmbeddedIdGrandparentEmbeddedIdDepTest extends BaseNonConfigCoreFunctionalTestCase { | ||
@Test | ||
public void testManyToOne() throws Exception { | ||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_firstName", metadata() ) ); | ||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_lastName", metadata() ) ); | ||
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata() ) ); | ||
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata() ) ); | ||
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata() ) ); | ||
|
||
assertTrue( SchemaUtil.isColumnPresent( "Policy", "dep_emp_firstName", metadata() ) ); | ||
assertTrue( SchemaUtil.isColumnPresent( "Policy", "dep_emp_lastName", metadata() ) ); | ||
assertTrue( SchemaUtil.isColumnPresent( "Policy", "type", metadata() ) ); | ||
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "firstName", metadata() ) ); | ||
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "lastName", metadata() ) ); | ||
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "name", metadata() ) ); | ||
|
||
|
||
final Employee e = new Employee(); | ||
e.empId = new EmployeeId(); | ||
e.empId.firstName = "Emmanuel"; | ||
e.empId.lastName = "Bernard"; | ||
final Session s = openSession(); | ||
s.getTransaction().begin(); | ||
s.persist( e ); | ||
final Dependent d = new Dependent(); | ||
d.emp = e; | ||
d.id = new DependentId(); | ||
d.id.name = "Doggy"; | ||
s.persist( d ); | ||
Policy p = new Policy(); | ||
p.dep = d; | ||
p.id = new PolicyId(); | ||
p.id.type = "Vet Insurance"; | ||
s.persist( p ); | ||
|
||
s.flush(); | ||
s.clear(); | ||
p = (Policy) s.get( Policy.class, p.id ); | ||
assertNotNull( p.dep ); | ||
assertEquals( e.empId.firstName, p.dep.emp.empId.firstName ); | ||
s.getTransaction().rollback(); | ||
s.close(); | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[]{Policy.class, Dependent.class, Employee.class}; | ||
} | ||
} |
Oops, something went wrong.