Hibernate version: 3.2 GA
Mapping documents: Using annotations
Code between sessionFactory.openSession() and session.close(): using OpenSessionInView pattern/code:
Full stack trace of any exception that occurs:
Code:
rg.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
at com.test.model.PhysicalLocation$$EnhancerByCGLIB$$e5762b71.setLastUpdate(<generated>)
Name and version of the database you are using:MySQL 4.1The generated SQL (show_sql=true): N/A (fails prior to sql call)Debug level Hibernate log excerpt:Code:
090-Processor23] DEBUG org.hibernate.jdbc.JDBCContext - after transaction begin
090-Processor23] DEBUG com.test.service.dao.impl.PhysicalLocationDaoImpl - saving an instance of: class com.test.model.PhysicalLocation$$EnhancerByCGLIB$$ad205672
090-Processor23] ERROR org.hibernate.LazyInitializationException - could not initialize proxy - the owning Session was closed
.LazyInitializationException: could not initialize proxy - the owning Session was closed
g.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
g.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
g.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
m.test.model.PhysicalLocation$$EnhancerByCGLIB$$ad205672.setLastUpdate(<generated>)
m.test.service.dao.impl.BaseDaoImpl.makePersistent(BaseDaoImpl.java:63)
n.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
n.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
n.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Relevant objects:
BaseEntity:
Code:
@MappedSuperclass
public class BaseEntity
{
protected Date lastUpdate;
protected String lastUpdateUser;
@Temporal(TemporalType.DATE)
public Date getLastUpdate() {
return lastUpdate;
}
.
.
.
Physical Location:
Code:
@Entity
@Table(name="coa_physicalLocation")
public class PhysicalLocation extends BaseEntity implements Serializable
{
private Long id;
private int locationCode;
private Location parentLocation;
private String description;
@ManyToOne(cascade = {CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinColumn(name="parentLocationId" )
public Location getParentLocation() {
return parentLocation;
}
.
.
.
Location (Which has several subclasses)
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="locationtype",
discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("location")
@Table(name="coa_location")
public abstract class Location extends BaseEntity implements Serializable
{
private Long id;
private String name;
private Location parent;
private int lowerBound;
private int upperBound;
private List<PhysicalLocation> physicalLocations = new LinkedList<PhysicalLocation>();
private Set<Location> childLocations = new TreeSet<Location>();
private String locationType = "country";
@OneToMany(fetch=FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy="parentLocation")
@JoinColumn(name="parentLocationId")
@OrderBy("locationCode")
public List<PhysicalLocation> getPhysicalLocations() {
return physicalLocations;
}
I'm doing a "long running transaction" in a JSF app - fetch the object for edit in one request, post the form/apply values, persist with saveOrUpdate().
Everything worked great until I put in the superclass with it's persistent properties, and now I'm getting the LazyInitializationException on a setter referencing the owning session being closed.
I've confirmed that everything works as I intend WITHOUT the superclass, but as soon as that is placed back in the hierarchy I get the exception above.
Any tips/suggestions would be greatly appreciated, as using the same superclass in other places in the app - doing essentially the same Crud operations works fine... I'm a bit confused and look forward to your insight. Any other thoughts are welcome too :)
Thanks,
[/code]