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