Testcase HHH-4294

This commit is contained in:
Guenther Demetz 2013-04-09 11:09:32 +02:00 committed by Brett Meyer
parent 08e3b16a95
commit b9fac8af11
5 changed files with 138 additions and 11 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.extralazy">
<class name="Child" >
<id name="id" >
<column name="ID" length="32" />
<generator class="uuid.hex" />
</id>
<property name="firstName" />
<many-to-one name="parent"
column="PARENT_ID"
class="Parent" />
</class>
</hibernate-mapping>

View File

@ -0,0 +1,36 @@
package org.hibernate.test.extralazy;
public class Child {
private String id;
private Parent parent;
private String firstName;
public void setParent(Parent parent) {
this.parent = parent;
}
public Parent getParent() {
return parent;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
}

View File

@ -22,29 +22,29 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.extralazy;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
/**
* @author Gavin King
*/
public class ExtraLazyTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] { "extralazy/UserGroup.hbm.xml" };
return new String[] { "extralazy/UserGroup.hbm.xml","extralazy/Parent.hbm.xml","extralazy/Child.hbm.xml" };
}
@Test
@ -240,5 +240,26 @@ public class ExtraLazyTest extends BaseCoreFunctionalTestCase {
}
@Test
@TestForIssue(jiraKey="HHH-4294")
public void testMap() {
Session session1 = openSession();
Transaction tx1 = session1.beginTransaction();
Parent parent = new Parent ();
Child child = new Child ();
child.setFirstName("Ben");
parent.getChildren().put(child.getFirstName(), child);
child.setParent(parent);
session1.save(parent);
tx1.commit();
session1.close();
// END PREPARE SECTION
Session session2 = openSession();
Parent parent2 = (Parent)session2.get(Parent.class, parent.getId());
Child child2 = parent2.getChildren().get(child.getFirstName()); // causes SQLGrammarException because of wrong condition: where child0_.PARENT_ID=? and child0_.null=?
assertNotNull(child2);
session2.close();
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.extralazy">
<class name="Parent" >
<!-- properties inherited from Adapter -->
<id name="id" >
<column name="TSGID" length="32" />
<generator class="uuid.hex" />
</id>
<map name="children" lazy="extra" inverse="true" cascade="save-update">
<key column="PARENT_ID" />
<map-key type="string" formula="firstName"/>
<one-to-many class="Child" />
</map>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,29 @@
package org.hibernate.test.extralazy;
import java.util.HashMap;
import java.util.Map;
public class Parent {
private String id;
private Map <String, Child> children = new HashMap<String, Child> ();
public void setChildren(Map <String, Child> children) {
this.children = children;
}
public Map <String, Child> getChildren() {
return children;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
}