-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Queries on subclass and batch-size
PostPosted: Wed Feb 16, 2005 6:30 pm 
Newbie

Joined: Thu Sep 02, 2004 4:19 am
Posts: 4
Location: Bergen - Norway
Hi,

I have some classes with the following declaration:

Code:
public class Company implements Serializable {
   private Long id;
   private String name;
   private Long type;
}

public class Advertiser extends Company {
}

public class Order {
   private Long id;
   private Advertiser advertiser;
}


I have specified batch-size=20 for the Company class, but when I execute queries against the Order table, Hibernate sets the batch-size to "1" for the Advertiser reference.
Is there a way to specify batch-size for the sub-class, either in the mapping file or programmatic (for instance something like "setBatchSize(Advertiser.class, 20)" ?

Thanks in advance for any reply.


Hibernate version:
3.0 beta4 and 2.1.8

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="data.Company" table="tbl_company" batch-size="20">
      <id name="id" column="com_id">
         <generator class="native"></generator>
      </id>
      <discriminator column="com_mtyp_id"></discriminator>
      <property name="name" column="com_companyname"></property>
      <property name="type" column="com_mtyp_id" insert="false" update="false"></property>

      <subclass name="data.Advertiser" discriminator-value="1">
      </subclass>
   </class>

   <class name="data.Order" table="tbl_orders">
      <id name="id" column="ord_id">
         <generator class="native"></generator>
      </id>
      <many-to-one name="advertiser" class="data.Advertiser" column="ord_cus_id"></many-to-one>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
         Query qry = session.createQuery("select ord from Order ord");
         List lst = qry.list();
         for (Iterator it = lst.iterator(); it.hasNext();) {
            Order ord = (Order)it.next();
            Company  adv = ord.getAdvertiser();
            if (adv != null) System.out.println(adv.getName());
         }
         System.out.println("size=" + lst.size());


Name and version of the database you are using:
MySQL 4.1.10

The generated SQL (show_sql=true):
Hibernate: select order0_.ord_id as ord1_, order0_.ord_cus_id as ord2_1_ from tbl_orders order0_

Hibernate: select advertiser0_.com_id as com1_0_, advertiser0_.com_companyname as com3_0_0_, advertiser0_.com_mtyp_id as com2_0_0_ from tbl_company advertiser0_ where advertiser0_.com_id=?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 10:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
wooops, this is a DTD bug.

edit your DTD to allow <subclass> to specify a batch-size


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 5:21 am 
Newbie

Joined: Thu Sep 02, 2004 4:19 am
Posts: 4
Location: Bergen - Norway
After modifying the DTD to allow batch-size to be specified on the <subclass>, the batch fetching works perfect.

Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.