Author: epbernard
Date: 2007-01-08 06:59:41 -0500 (Mon, 08 Jan 2007)
New Revision: 11019
Added:
trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java
trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
Log:
Testcase for HHH-2292
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2007-01-07
01:05:14 UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2007-01-08
11:59:41 UTC (rev 11019)
@@ -20,7 +20,7 @@
}
public String[] getMappings() {
- return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml",
"ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml" };
+ return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml",
"ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml",
"ops/Competition.hbm.xml" };
}
public String getCacheConcurrencyStrategy() {
Added: trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml 2007-01-07 01:05:14
UTC (rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Competition.hbm.xml 2007-01-08 11:59:41
UTC (rev 11019)
@@ -0,0 +1,33 @@
+<?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.ops">
+
+ <class name="Competition">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <list name="competitors"
+ cascade="persist,merge"
+ table="COMPET_ION_OR">
+ <key column="TION_ID"/>
+ <list-index column="INDEX_COL"/>
+ <many-to-many class="Competitor" column="TOR_ID" />
+ </list>
+ </class>
+
+ <class name="Competitor">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <property name="name"/>
+ </class>
+
+</hibernate-mapping>
+
Added: trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java 2007-01-07 01:05:14 UTC
(rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Competition.java 2007-01-08 11:59:41 UTC
(rev 11019)
@@ -0,0 +1,31 @@
+//$Id: $
+package org.hibernate.test.ops;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Competition {
+ private Integer id;
+
+ private List competitors = new ArrayList();
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public List getCompetitors() {
+ return competitors;
+ }
+
+ public void setCompetitors(List competitors) {
+ this.competitors = competitors;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java 2007-01-07 01:05:14 UTC
(rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Competitor.java 2007-01-08 11:59:41 UTC
(rev 11019)
@@ -0,0 +1,34 @@
+//$Id: $
+package org.hibernate.test.ops;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Competitor {
+ public Integer id;
+ private String name;
+
+
+ public Competitor() {
+ }
+
+ public Competitor(String name) {
+ this.name = name;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2007-01-07 01:05:14 UTC
(rev 11018)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2007-01-08 11:59:41 UTC
(rev 11019)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
@@ -569,6 +570,33 @@
cleanup();
}
+ public void testMergeManyToManyWithColelctionDeference() throws Exception {
+ Competition competition = new Competition();
+ competition.getCompetitors().add( new Competitor("Name") );
+ competition.getCompetitors().add( new Competitor() );
+ competition.getCompetitors().add( new Competitor() );
+ Session s = openSession( );
+ Transaction tx = s.beginTransaction();
+ s.persist( competition );
+ s.flush();
+ s.clear();
+ List newComp = new ArrayList();
+ newComp.add( competition.getCompetitors().get(0) );
+ newComp.add( new Competitor() );
+ ( (Competitor) newComp.get(0) ).setName( "Name2" );
+ competition.setCompetitors( newComp );
+ competition = (Competition) s.merge( competition );
+ s.flush();
+ s.clear();
+ competition = (Competition) s.get( Competition.class, competition.getId() );
+ assertEquals( 2, competition.getCompetitors().size() );
+ assertEquals( "Name2", ( (Competitor) competition.getCompetitors().get(0)
).getName() );
+ tx.rollback();
+ s.close();
+
+ cleanup();
+ }
+
private void cleanup() {
Session s = openSession();
s.beginTransaction();
Show replies by date