Ho un problema di prestazioni nel mio mapping molti-a-uno. Quando eseguo il debug della query SQL nel file di registro, la query principale è ok, ma dopo ho un'altra query che rappresenta il mapping di oggetti molti-a-uno.Il caricamento lenta di ibernazione non funziona con il mapping molti-a-uno
Entity.hbm.xml:
<?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="com.omb.database.mapping.MyEntity" table="MY_ENTITY">
<id name="id" type="java.lang.Integer">
<column name="ENTITY_ID"/>
<generator class="sequence">
<param name="sequence">SEQ_MY_ENTITY</param>
</generator>
</id>
<property name="prop1" type="string" column="PROP1" />
<many-to-one name="object1" column="OBJECT1_ID" class="com.omb.database.mapping.Object1" />
<many-to-one name="object2" column="OBJECT2_ID" class="com.omb.database.mapping.Object2" />
</class>
</hibernate-mapping>
Object1.hbm.xml:
<?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 default-lazy="true">
<class name="com.omb.database.mapping.Object1" table="TABLE_OBJECT_1">
<id name="id" type="java.lang.Integer" column="OBJECT1_ID" />
<property name="label" type="string" column="LABEL_OBJECT_1" length="15" />
</class>
</hibernate-mapping>
Object2.hbm.xml:
<?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 default-lazy="true">
<class name="com.omb.database.mapping.Object2" table="TABLE_OBJECT_2">
<id name="id" type="java.lang.Integer" column="OBJECT2_ID" />
<property name="label" type="string" column="LABEL_OBJECT_2" length="15" />
</class>
</hibernate-mapping>
Query HBM:
public List<Entity> findByObject1Id(Integer object1Id) throws DataAccesException {
List<Entity> results = null;
try {
Query query = this.getSession().createQuery(
"from Entity ent where ent.object1.id = :object1Id");
query.setParameter("object1Id", object1Id);
results = query.list();
} catch (HibernateException hbe) {
throw new DataAccesException(hbe);
}
return results;
}
in pom.xml
<!-- Hibernate 3 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
</exclusion>
</exclusions>
</dependency>
Si prega di mostrare le domande che state vedendo e indicare la vostra domanda esatta. Stai chiedendo perché vedi queste domande? Stai chiedendo come modificare il tuo codice/configurazione per modificare in qualche modo le query? – Rob