Hibernate version: 3.1
Full stack trace of any exception that occurs:
Code:
07.06.2006 13:17:11 org.hibernate.LazyInitializationException <init>
SCHWERWIEGEND: could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at ams.uptoip.server.user.management.model.address.UsermgrZipcode$$EnhancerByCGLIB$$46616efc.getCode(<generated>)
at ams.uptoip.server.user.management.address.UsermgrAddressHistoryBeanTest.testGet(UsermgrAddressHistoryBeanTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Name and version of the database you are using: Ingres
ProblembeschreibungHi!
Ich habe folgende
Tabellen:
Code:
CREATE TABLE usermgr_city (
id INTEGER NOT NULL,
name VARCHAR(30) NOT NULL CHECK(name <> ''),
PRIMARY KEY(id)
);
CREATE TABLE usermgr_address (
id INTEGER NOT NULL,
city INTEGER NOT NULL
PRIMARY KEY(id),
FOREIGN KEY(city) REFERENCES usermgr_city(id)
);
CREATE TABLE usermgr_address_history (
id INTEGER NOT NULL,
address INTEGER NOT NULL,
from DATE NOT NULL,
to DATE,
parent INTEGER,
PRIMARY KEY(id),
FOREIGN KEY(address) REFERENCES usermgr_address(id),
FOREIGN KEY(parent) REFERENCES usermgr_address_history(id)
);
und ich habe folgende
POJOs:
Code:
@Entity
@Table(name = "usermgr_city", schema = "ingres", uniqueConstraints = {})
public class UsermgrCity implements java.io.Serializable
{
...
@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 30)
public String getName()
{
return this.name;
}
...
} // UsermgrCity
@Entity
@Table(name = "usermgr_address", schema = "ingres", uniqueConstraints = {})
public class UsermgrAddress implements java.io.Serializable
{
...
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "city", unique = false, nullable = false, insertable = true, updatable = true)
public UsermgrCity getUsermgrCity()
{
return this.usermgrCity;
}
...
} // UsermgrAddress
@Entity
@Table(name = "usermgr_address_history", schema = "ingres", uniqueConstraints = {})
public class UsermgrAddressHistory implements java.io.Serializable
{
...
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "address", unique = false, nullable = false, insertable = true, updatable = true)
public UsermgrAddress getUsermgrAddress()
{
return this.usermgrAddress;
}
...
} // UsermgrAddressHistory
Die Klasse UsermgrAddress besteht jeden Test einwandfrei, nur wenn ich folgenden Code ausführen möchte, bekomme ich oben angeführte Fehlermeldung:
addressHistory.getId(); //
Funktioniert
addressHistory.getFrom(); //
Funktioniert
UsermgrAddress address = addressHistory.getUsermgrAddress(); //
Funktioniert
address.getId() == 1; //
Funktioniert
address.getUsermgrCity().getName().equals(CITY); //
FEHLER
Meine Frage nun:
Wie kann ich andere Objekte hinzufetchen (nicht alle so wie bei EAGER, sondern nur ausgewählte). Oder muss ich EAGER verwenden?
Danke!