Subject | Hibernate 2.1.8 lazy fetch trouble with Jaybird RC 2 |
---|---|
Author | rockxwre |
Post date | 2005-10-10T10:00:38Z |
Hi all,
I'm having some trouble with the latest RC (2) in combination with
Hibernate 2.1.8.
This is the problem: when I try to fetch multiple records from a
Hibernate query, the following exception occures:
net.sf.hibernate.LazyInitializationException: Hibernate lazy
instantiation problem
at net.sf.hibernate.impl.IteratorImpl.next
(IteratorImpl.java:133)
at nl.asknow.model.CustomerTest.testLazyIterator
(CustomerTest.java:36)
...
Caused by: org.firebirdsql.jdbc.FBSQLException: The result set is
closed
at org.firebirdsql.jdbc.FBResultSet.checkCursorMove
(FBResultSet.java:217)
at org.firebirdsql.jdbc.FBResultSet.next
(FBResultSet.java:249)
at org.apache.commons.dbcp.DelegatingResultSet.next
(DelegatingResultSet.java:168)
at net.sf.hibernate.impl.IteratorImpl.postNext
(IteratorImpl.java:85)
at net.sf.hibernate.impl.IteratorImpl.next
(IteratorImpl.java:127)
... 16 more
It seems that the result set is closed, while Hibernate expects it
to be open. With Jaybird 1.5.x it works just fine.
This time I was able to make a testcase for this. Here it comes (two
classes):
The model class "Customer", includes XDoclet to create the correct
schema.
/**
* @...
* select-before-update="true"
* dynamic-update="true"
* dynamic-insert="true"
*
* @...
* name = "allCustomers"
* query = "from Customer customer"
*/
public class Customer {
private Integer id;
private String name;
/**
* @...
* column="C_ID"
* not-null="true"
* generator-class="native"
*
* @...-param
* name="sequence"
* value="CUSTOMER_GEN"
*/
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* @...
* column="C_NAME"
* length="128"
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
TestCase, the method setUp() should be worked out to obtain a valid
Hibernate session...
import java.util.Iterator;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import junit.framework.TestCase;
public class CustomerTest extends TestCase {
private Session session;
protected void setUp() throws Exception {
session = ...
}
protected void tearDown() throws HibernateException {
session.close();
}
public void testLazyIterator() throws HibernateException {
Query query = session.getNamedQuery("allCustomers");
Iterator iterator = query.iterate();
while (iterator.hasNext()) {
// This line will fail...
iterator.next();
}
}
}
Is this a bug? Or am I doing something wrong (besides not using
Hibernate 3 :-).
Thanks,
Ramon Rockx
I'm having some trouble with the latest RC (2) in combination with
Hibernate 2.1.8.
This is the problem: when I try to fetch multiple records from a
Hibernate query, the following exception occures:
net.sf.hibernate.LazyInitializationException: Hibernate lazy
instantiation problem
at net.sf.hibernate.impl.IteratorImpl.next
(IteratorImpl.java:133)
at nl.asknow.model.CustomerTest.testLazyIterator
(CustomerTest.java:36)
...
Caused by: org.firebirdsql.jdbc.FBSQLException: The result set is
closed
at org.firebirdsql.jdbc.FBResultSet.checkCursorMove
(FBResultSet.java:217)
at org.firebirdsql.jdbc.FBResultSet.next
(FBResultSet.java:249)
at org.apache.commons.dbcp.DelegatingResultSet.next
(DelegatingResultSet.java:168)
at net.sf.hibernate.impl.IteratorImpl.postNext
(IteratorImpl.java:85)
at net.sf.hibernate.impl.IteratorImpl.next
(IteratorImpl.java:127)
... 16 more
It seems that the result set is closed, while Hibernate expects it
to be open. With Jaybird 1.5.x it works just fine.
This time I was able to make a testcase for this. Here it comes (two
classes):
The model class "Customer", includes XDoclet to create the correct
schema.
/**
* @...
* select-before-update="true"
* dynamic-update="true"
* dynamic-insert="true"
*
* @...
* name = "allCustomers"
* query = "from Customer customer"
*/
public class Customer {
private Integer id;
private String name;
/**
* @...
* column="C_ID"
* not-null="true"
* generator-class="native"
*
* @...-param
* name="sequence"
* value="CUSTOMER_GEN"
*/
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* @...
* column="C_NAME"
* length="128"
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
TestCase, the method setUp() should be worked out to obtain a valid
Hibernate session...
import java.util.Iterator;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import junit.framework.TestCase;
public class CustomerTest extends TestCase {
private Session session;
protected void setUp() throws Exception {
session = ...
}
protected void tearDown() throws HibernateException {
session.close();
}
public void testLazyIterator() throws HibernateException {
Query query = session.getNamedQuery("allCustomers");
Iterator iterator = query.iterate();
while (iterator.hasNext()) {
// This line will fail...
iterator.next();
}
}
}
Is this a bug? Or am I doing something wrong (besides not using
Hibernate 3 :-).
Thanks,
Ramon Rockx