[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3230?page=c...
]
Diego del Río commented on HHH-3230:
------------------------------------
Gail, the test succeeds if the exception is thrown, therefore is still an issue in
Hibernate 3.6.1-SNAPSHOT.
But I am realizing that it's a bit confusing, so this is the version of the test that
fails if the exception is thrown and succeeds if the exception isn´t thrown
{noformat}
package org.headlesspigs.test;
import org.headlesspigs.domainmodel.Invoice;
import org.headlesspigs.domainmodel.WorkingPerson;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit.functional.FunctionalTestCase;
public class ProxyNarrowingTest extends FunctionalTestCase {
public ProxyNarrowingTest(String string) {
super(string);
}
public String[] getMappings() {
return new String[] { "Person.hbm.xml", "Invoice.hbm.xml" };
}
public String getBaseForMappings() {
return "org/headlesspigs/domainmodel/";
}
public boolean createSchema() {
return true;
}
public void testNarrowingProxy() throws Exception {
Session s = null;
Transaction tx = null;
WorkingPerson p1 = null;
WorkingPerson p2 = null;
Invoice inv = null;
try {
s = this.openSession();
tx = s.beginTransaction();
p1 = new WorkingPerson("Adrian");
p2 = new WorkingPerson("Batista", p1);
inv = new Invoice("A-462", p1, p2);
s.save(inv);
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
if (s != null) {
s.close();
}
}
try {
s = this.openSession();
tx = s.beginTransaction();
inv = (Invoice) s.load(Invoice.class, inv.getId());
assertEquals("A-462", inv.getNumber());
// The following line causes the proxy to the emitter Person to be
// initialized. During this initialization, a proxy to
// the referee person is found but its type is Person and not
// WorkingPerson as needed, so Hibernate creates another proxy to
// the referee, this time of type WorkingPerson, replacing the old
// one.
assertEquals("Batista", inv.getEmitter().getName());
s.getEntityName(inv.getReceiver());
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
if (s != null) {
s.close();
}
}
}
}
{noformat}
getEntityName() throws org.hibernate.TransientObjectException: proxy
was not associated with the session
--------------------------------------------------------------------------------------------------------
Key: HHH-3230
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3230
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.2.2, 3.6.0
Environment: Mac OS X, JDK 1.5
Reporter: Howard M. Lewis Ship
Attachments: Debugging output from IDEA.jpg, NarrowingProxyTestCase.zip
I'm retrieving an entity that contains a OneToMany relationship.
The master entity is retrieved, within a transaction, via
Session.get(Class,Serializable).
@Entity
public class MapUnitSurvey extends ActiveDO
{
@ManyToOne(fetch = FetchType.LAZY)
private VegetationType vegetationType;
}
@Entity
public class VegetationType extends AbstractEnum
{
}
ActiveDO and AbstractEnum are abstract base classes with @MappedSuperclass.
I retrieve the vegationType:
VegetationType type = survey.getVegetationType();
Then I need the type's entity name
String entityName = session.getEntityName(type);
This fails with the TransientObjectException.
Inspecting with the debugger, I see that type is a CGLIB-enhanced proxy, and that
there's a fully initialized bean in the target field of the proxy. I'll attach a
screenshot of some debugging data.
In summary; the entity was retrieved via a lazy fetch, appears the be correct, seems to
be in the session and yet the exception occurs.
I've tried to resolve this by re-fetching the object from the session, and a few
other tries, with no luck.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira