Hi everyone,
I'm a new user of Hibernate and I have a strange problem :
I've 2 classes : Customer AND Story which look like :
Code:
public class Customer {
private long id;
private String number;
private List historique = new ArrayList();
public Customer() {
}
public void setId(long newId) {
id=newId;
}
public long getId() {
return id;
}
public void setNumber(String newNumber) {
this.number=newNumber;
}
public String getNum_prospect() {
return this.num_prospect;
}
}
Code:
public class Story {
private long id;
private Calendar dateHisto;
private Customer customer;
public Story() {
}
public void setId(long newId) {
id=newId;
}
public long getId() {
return id;
}
public void setDateHisto(Calendar newDateHisto) {
if (newDateHisto!=null)
this.dateHisto=newDateHisto;
}
public Calendar getDateHisto() {
return this.dateHisto;
}
public void setCustomer(Customer newCustomer) {
this.customer=newCustomer;
}
public Customer getCustomer() {
return this.customer;
}
}
And the corresponding mapping file looks like :
Code:
<?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 package="com.abw.beans">
<class name="com.abw.beans.Customer" table="PROSPECT" lazy="true">
<id name="id" column="ID_PROSPECT">
<generator class="increment" />
</id>
<property name="number" column="NUM_PROSPECT" />
<bag name="story" lazy="true" cascade="all" order-by="DATE_HISTO">
<key column="id_prospect"/>
<one-to-many class="Historique"/>
</bag>
</class>
</hibernate-mapping>
Code:
<?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 package="com.abw.beans">
<class name="com.abw.beans.Story" table="HISTORIQUE" lazy="true">
<id name="id" column="ID_HISTORIQUE">
<generator class="increment" />
</id>
<property name="dateHisto" column="DATE_HISTO" />
<many-to-one name="customer" column="id_prospect" not-null="true"/>
</class>
</hibernate-mapping>
And my problem is :
When i make a simple request like :
Code:
public Vector getCustomer(int max_result,int deb_result) {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery("select customer from Customer");
q.setMaxResults(max_result);
q.setFirstResult(deb_result);
List result = q.list();
//tx.commit();
Vector v = new Vector(result.size());
v.addAll(result);
return v;
}
AND no reference (at all !!!) to the class Story
When I see the SQL log I can see query like :
select ... from Customer where ...
select ... from Story where ...
select ... from Story where ...
select ... from Story where ...
select ... from Story where ...
...
So my question/problem is :
WHY hibernate make request to the Story objet ???
I have set lazy to true and NO reference to the object !!!
I have read a lot of documentation and I have found no answer.
So please help me !!!!