HHH-9370 : Unidirectional one-to-many with key that is property-ref (test case)

This commit is contained in:
Gail Badner 2015-04-01 16:13:13 -07:00
parent 7019db74fb
commit 02e2644676
5 changed files with 79 additions and 5 deletions

View File

@ -0,0 +1,41 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, 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.unidir;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
/**
* @author Gail Badner
*/
@TestForIssue( jiraKey = "HHH-9370")
@FailureExpected( jiraKey = "HHH-9370")
public class BackrefPropertyRefTest extends BackrefTest {
@Override
protected String[] getMappings() {
return new String[] { "unidir/ParentChildPropertyRef.hbm.xml" };
}
}

View File

@ -53,8 +53,8 @@ public class BackrefTest extends BaseCoreFunctionalTestCase {
public void testBackRef() {
Session s = openSession();
Transaction t = s.beginTransaction();
Parent p = new Parent("Marc");
Parent p2 = new Parent("Nathalie");
Parent p = new Parent("Marc", 123456789);
Parent p2 = new Parent("Nathalie", 987654321 );
Child c = new Child("Elvira");
Child c2 = new Child("Blase");
p.getChildren().add(c);
@ -92,7 +92,7 @@ public class BackrefTest extends BaseCoreFunctionalTestCase {
s.close();
s = openSession();
t = s.beginTransaction();
Parent p3 = new Parent("Marion");
Parent p3 = new Parent("Marion", 543216789);
p3.getChildren().add( new Child("Gavin") );
s.merge(p3);
t.commit();
@ -110,7 +110,7 @@ public class BackrefTest extends BaseCoreFunctionalTestCase {
public void testBackRefToProxiedEntityOnMerge() {
Session s = openSession();
s.beginTransaction();
Parent me = new Parent( "Steve" );
Parent me = new Parent( "Steve", 192837465 );
me.getChildren().add( new Child( "Joe" ) );
s.persist( me );
s.getTransaction().commit();

View File

@ -8,10 +8,12 @@ import java.util.List;
*/
public class Parent {
private String name;
private long ssn;
private List children = new ArrayList();
Parent() {}
public Parent(String name) {
public Parent(String name, long ssn) {
this.name = name;
this.ssn = ssn;
}
public List getChildren() {
return children;
@ -25,4 +27,10 @@ public class Parent {
public void setName(String name) {
this.name = name;
}
public long getSsn() {
return ssn;
}
public void setSsn(long ssn) {
this.ssn = ssn;
}
}

View File

@ -8,6 +8,7 @@
<class name="Parent">
<id name="name"/>
<property name="ssn" unique="true"/>
<list name="children" cascade="persist,merge">
<key column="parentName" not-null="true"/>
<list-index column="sibling"/>

View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="org.hibernate.test.unidir">
<class name="Parent">
<id name="name"/>
<property name="ssn" unique="true"/>
<list name="children" cascade="persist,merge">
<key column="parentSsn" not-null="true" property-ref="ssn"/>
<list-index column="sibling"/>
<one-to-many class="Child"/>
</list>
</class>
<class name="Child">
<id name="name"/>
<property name="age" not-null="true"/>
</class>
</hibernate-mapping>