Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="entity.Address" table="address">
<id name="id" column="id" type="integer" access="field">
<generator class="increment"/>
</id>
<property
name="street"
column="street"
type="string"
access="field"/>
<property
name="apt"
column="apt"
type="string"
access="field"/>
<property
name="date"
column="date"
type="java.util.Date"
access="field"/>
<many-to-one
name="user"
column="user_id"
class="entity.User"
access="field"
lazy="false"
/>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="entity.User" table="user" >
<id name="id" column="id" type="integer" access="field">
<generator class="increment"/>
</id>
<property
name="name"
column="name"
type="string"
access="field"/>
<property
name="surname"
column="surname"
type="string"
access="field"/>
<property
name="pass"
column="pass"
type="string"
access="field"/>
<property
name="type"
column="type"
type="string"
access="field"/>
<set name="addresses" cascade="all" lazy="false" fetch="join" access="field">
<key column="user_id"/>
<one-to-many class="entity.Address"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using: MySql 4.0.15
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
First of all i must say that i am new to hibernate.
I make two classes name User and Address and make biderectional relation between them.
in the database there are 100 users and for each of these users there are 1000 addresses (test code).
when i get the users (address also since non-lazy) like below
Session session = null;
Transaction tx = null;
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query query = session.createQuery( "from User" );
List list=null;
try{
list = query.list();
session.close();
}
catch(Exception ex){
ex.printStackTrace();
}
it takes too many times (nearly 10 seconds). what is wrong here.
Before sending this message i make a search on the forum but cannot solve the problem.