|
From: <hib...@li...> - 2006-08-04 20:29:24
|
Author: ste...@jb...
Date: 2006-08-04 16:29:21 -0400 (Fri, 04 Aug 2006)
New Revision: 10223
Added:
trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java
trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java
trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java
Log:
HHH-1954 : proxies and eviction
Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java 2006-08-04 20:17:12 UTC (rev 10222)
+++ trunk/Hibernate3/test/org/hibernate/test/proxy/Container.java 2006-08-04 20:29:21 UTC (rev 10223)
@@ -11,6 +11,7 @@
private Long id;
private String name;
private Owner owner;
+ private Info info;
private Set dataPoints = new HashSet();
public Container() {
@@ -44,6 +45,14 @@
this.owner = owner;
}
+ public Info getInfo() {
+ return info;
+ }
+
+ public void setInfo(Info info) {
+ this.info = info;
+ }
+
public Set getDataPoints() {
return dataPoints;
}
Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml 2006-08-04 20:17:12 UTC (rev 10222)
+++ trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.hbm.xml 2006-08-04 20:29:21 UTC (rev 10223)
@@ -26,12 +26,20 @@
<property name="name" unique="true"/>
</class>
+ <class name="Info">
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <property name="details"/>
+ </class>
+
<class name="Container">
<id name="id">
<generator class="increment"/>
</id>
<property name="name"/>
<many-to-one name="owner" class="Owner" column="owner_name" property-ref="name" cascade="all"/>
+ <many-to-one name="info" class="Info" column="info_id" cascade="all"/>
<set name="dataPoints" lazy="true" inverse="false" cascade="all">
<key column="c_id"/>
<one-to-many class="DataPoint"/>
Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java 2006-08-04 20:17:12 UTC (rev 10222)
+++ trunk/Hibernate3/test/org/hibernate/test/proxy/DataPoint.java 2006-08-04 20:29:21 UTC (rev 10223)
@@ -12,6 +12,16 @@
private BigDecimal x;
private BigDecimal y;
private String description;
+
+ public DataPoint() {
+ }
+
+ public DataPoint(BigDecimal x, BigDecimal y, String description) {
+ this.x = x;
+ this.y = y;
+ this.description = description;
+ }
+
/**
* @return Returns the description.
*/
Added: trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java 2006-08-04 20:17:12 UTC (rev 10222)
+++ trunk/Hibernate3/test/org/hibernate/test/proxy/Info.java 2006-08-04 20:29:21 UTC (rev 10223)
@@ -0,0 +1,34 @@
+package org.hibernate.test.proxy;
+
+/**
+ * todo: describe Info
+ *
+ * @author Steve Ebersole
+ */
+public class Info {
+ private Long id;
+ private String details;
+
+ public Info() {
+ }
+
+ public Info(String details) {
+ this.details = details;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getDetails() {
+ return details;
+ }
+
+ public void setDetails(String details) {
+ this.details = details;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-08-04 20:17:12 UTC (rev 10222)
+++ trunk/Hibernate3/test/org/hibernate/test/proxy/ProxyTest.java 2006-08-04 20:29:21 UTC (rev 10223)
@@ -13,6 +13,7 @@
import org.hibernate.Transaction;
import org.hibernate.FlushMode;
import org.hibernate.ObjectNotFoundException;
+import org.hibernate.LazyInitializationException;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.impl.SessionImpl;
@@ -237,6 +238,51 @@
s.close();
}
+ public void testProxyEviction() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Container container = new Container( "container" );
+ container.setOwner( new Owner( "owner" ) );
+ container.setInfo( new Info( "blah blah blah" ) );
+ container.getDataPoints().add( new DataPoint( new BigDecimal( 1 ), new BigDecimal( 1 ), "first data point" ) );
+ container.getDataPoints().add( new DataPoint( new BigDecimal( 2 ), new BigDecimal( 2 ), "second data point" ) );
+ s.save( container );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Container c = ( Container ) s.load( Container.class, container.getId() );
+ assertFalse( Hibernate.isInitialized( c ) );
+ s.evict( c );
+ try {
+ c.getName();
+ fail( "expecting LazyInitializationException" );
+ }
+ catch( LazyInitializationException e ) {
+ // expected result
+ }
+
+ c = ( Container ) s.load( Container.class, container.getId() );
+ assertFalse( Hibernate.isInitialized( c ) );
+ Info i = c.getInfo();
+ assertTrue( Hibernate.isInitialized( c ) );
+ assertFalse( Hibernate.isInitialized( i ) );
+ s.evict( c );
+ try {
+ i.getDetails();
+ fail( "expecting LazyInitializationException" );
+ }
+ catch( LazyInitializationException e ) {
+ // expected result
+ }
+
+ s.delete( c );
+
+ t.commit();
+ s.close();
+ }
+
protected String[] getMappings() {
return new String[] { "proxy/DataPoint.hbm.xml" };
}
|