Hibernate Version 3.0.5 with Spring 1.2.1
PostgreSQL 8
I think the sql generated is too complex.
It is really simple. An entity of 'TEILESTAM' is associated with
some entities of 'BESCHREIB' that contains localized descriptions.
If I load an entity of 'TEILESTAM', the sql is ok. But if I access
the 'beschreibungenInternal' field, hibernate creates a sql-statement
for the entities of 'BESCHREIB' which looks too complicated for me.
Generated SQL:
select
beschreibu0_.MA as MA1_,
beschreibu0_.TEILENR as TEILENR1_,
beschreibu0_.KEY as KEY1_,
beschreibu0_.MA as MA0_,
beschreibu0_.TEILENR as TEILENR0_,
beschreibu0_.KEY as KEY0_,
beschreibu0_.TEXT as TEXT0_0_
from
BESCHREIB beschreibu0_
where
beschreibu0_.MA='MMD' and beschreibu0_.TEILENR='000000033'
ResultSet:
ma1_ teilenr1_ key1_ ma0_ teilenr0_ key0_ text0_0_
---- --------- ----- ---- --------- ----- ---------------------------
MMD 000000033 enGB MMD 000000033 enGB First aid box
MMD 000000033 frFR MMD 000000033 frFR Boîte à pansements
MMD 000000033 itIT MMD 000000033 itIT Scatola del pronto soccorso
So my question is, why are the entries 'ma', 'teilenr' and 'key' retrieved twice ?
I don't know the internals, how hibernate does its mapping.
Is it a mistake in my mapping or .... ?????
My mappings:
teilestam.hbm.xml:
<hibernate-mapping auto-import="true" default-lazy="false" package="de.holger.model">
<class name="Teilestamm" table="TEILESTAM">
<composite-id name="id" class="TeilestammId">
<key-property name="ma" column="MA" type="string" length="5"/>
<key-property name="teilenr" column="TEILENR" type="string" length="20"/>
</composite-id>
<property name="beschreibung" column="BESCHREIBUNG" length="254" type="string" />
<set name="beschreibungenInternal" inverse="false">
<key>
<column name="MA" />
<column name="TEILENR" />
</key>
<one-to-many class="Beschreib" />
</set>
</class>
</hibernate-mapping>
beschreib.hbm.xml:
<hibernate-mapping auto-import="true" default-lazy="false" package="de.holger.model">
<class name="Beschreib" table="BESCHREIB">
<composite-id name="id" class="BeschreibId">
<key-property name="ma" column="MA" type="string" length="5"/>
<key-property name="teilenr" column="TEILENR" type="string" length="20"/>
<key-property name="key" column="KEY" type="string" length="5"/>
</composite-id>
<property name="text" column="TEXT" type="string" length="30"/>
</class>
</hibernate-mapping>
Spring:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>/de/holger/hibernate/maps/beschreib.hbm.xml</value>
<value>/de/holger/hibernate/maps/teilestam.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="merge">
<bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
</entry>
</map>
</property>
</bean>
Thank you in advance,
Holger
|