Skip to content

Commit

Permalink
HHH-9370 : Unidirectional one-to-many with key that is property-ref (…
Browse files Browse the repository at this point in the history
…test case)
  • Loading branch information
gbadner committed Apr 1, 2015
1 parent 7019db7 commit 02e2644
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
@@ -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" };
}

}
Expand Up @@ -53,8 +53,8 @@ protected Class<?>[] getAnnotatedClasses() {
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);
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testBackRef() {
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();
Expand All @@ -110,7 +110,7 @@ public void testBackRef() {
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();
Expand Down
Expand Up @@ -8,10 +8,12 @@
*/
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;
Expand All @@ -25,4 +27,10 @@ public String getName() {
public void setName(String name) {
this.name = name;
}
public long getSsn() {
return ssn;
}
public void setSsn(long ssn) {
this.ssn = ssn;
}
}
Expand Up @@ -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"/>
Expand Down
@@ -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>

0 comments on commit 02e2644

Please sign in to comment.