aspose file tools*
The moose likes Object Relational Mapping and the fly likes Optimisation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Optimisation problem" Watch "Optimisation problem" New topic
Author

Optimisation problem

HuGuEs HuGuEs
Greenhorn

Joined: Aug 03, 2005
Posts: 1
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;
}
}


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 :

<?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>


<?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 :
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 !!!
_________________
HuGuEs
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

"Hugues"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Optimisation problem