Created
July 4, 2013 17:51
-
-
Save lukasz-antoniak/5929345 to your computer and use it in GitHub Desktop.
Dynamic-map and one-to-one relation mapped with intersection table
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
diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/DynamicMapOneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/DynamicMapOneToOneTest.java | |
index 215c088..1a6a535 100644 | |
--- a/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/DynamicMapOneToOneTest.java | |
+++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/DynamicMapOneToOneTest.java | |
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull; | |
public class DynamicMapOneToOneTest extends BaseCoreFunctionalTestCase { | |
@Override | |
public String[] getMappings() { | |
- return new String[] { "onetoone/nopojo/Person.hbm.xml" }; | |
+ return new String[] { "onetoone/nopojo/Person.hbm.xml", "onetoone/nopojo/Marriage.hbm.xml" }; | |
} | |
@Override | |
@@ -74,5 +74,31 @@ public class DynamicMapOneToOneTest extends BaseCoreFunctionalTestCase { | |
assertEquals( addressStats.getFetchCount(), 0 ); | |
} | |
+ @Test | |
+ public void testJoinTableInsertOrder() { | |
+ final Session session = openSession(); | |
+ | |
+ session.getTransaction().begin(); | |
+ final Map<String, Object> wifeRecord = new HashMap<String, Object>(); | |
+ wifeRecord.put( "id", 1l ); | |
+ wifeRecord.put( "name", "Kinga" ); | |
+ wifeRecord.put( "husband_id", 2l ); | |
+ final Map<String, Object> husbandRecord = new HashMap<String, Object>(); | |
+ husbandRecord.put( "id", 2l ); | |
+ husbandRecord.put( "name", "Lukasz" ); | |
+ husbandRecord.put( "wife_id", 1l ); | |
+ session.save( "Wife", wifeRecord ); | |
+ session.save( "Husband", husbandRecord ); | |
+ session.getTransaction().commit(); | |
+ | |
+ session.clear(); | |
+ | |
+ session.getTransaction().begin(); | |
+ assertNotNull( session.get( "Wife", 1l ) ); | |
+ assertNotNull( session.get( "Husband", 2l ) ); | |
+ session.getTransaction().commit(); | |
+ | |
+ session.close(); | |
+ } | |
} | |
diff --git a/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/Marriage.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/Marriage.hbm.xml | |
new file mode 100644 | |
index 0000000..b54969b | |
--- /dev/null | |
+++ b/hibernate-core/src/test/java/org/hibernate/test/onetoone/nopojo/Marriage.hbm.xml | |
@@ -0,0 +1,22 @@ | |
+<?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> | |
+ <class entity-name="Wife"> | |
+ <id name="id" type="long"/> | |
+ <property name="name" not-null="true" type="string"/> | |
+ <join table="wife_husband" optional="true"> | |
+ <key column="wife_id"/> | |
+ <property name="husband_id" type="long" /> | |
+ </join> | |
+ </class> | |
+ <class entity-name="Husband"> | |
+ <id name="id" type="long"/> | |
+ <property name="name" not-null="true" type="string"/> | |
+ <join table="wife_husband" optional="true"> | |
+ <key column="husband_id"/> | |
+ <property name="wife_id" type="long" /> | |
+ </join> | |
+ </class> | |
+</hibernate-mapping> | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment