Thanks nordborg, but i already tried to implement a filter solution. I only could enable them in my environment DAO, but it dont works. Here is the generated SQL Statement:
Code:
select
ecmenviron0_.server_id as server1_1_,
ecmenviron0_.environment_data_id as environm2_1_,
ecmenviron1_.environment_id as environm1_6_0_,
ecmenviron1_.runtime_environment_Id as runtime2_6_0_,
ecmenviron1_.name as name6_0_,
ecmenviron1_.context as context6_0_,
ecmenviron1_.version as version6_0_
from
ecm_server_environment_data ecmenviron0_
left outer join
ecm.ecm_environment_data ecmenviron1_
on ecmenviron0_.environment_data_id=ecmenviron1_.environment_id
where
ecmenviron0_.server_id=?
Hibernate:
select
ecmenviron0_.server_id as server1_1_,
ecmenviron0_.environment_data_id as environm2_1_,
ecmenviron1_.environment_id as environm1_6_0_,
ecmenviron1_.runtime_environment_Id as runtime2_6_0_,
ecmenviron1_.name as name6_0_,
ecmenviron1_.context as context6_0_,
ecmenviron1_.version as version6_0_
from
ecm_server_environment_data ecmenviron0_
left outer join
ecm.ecm_environment_data ecmenviron1_
on ecmenviron0_.environment_data_id=ecmenviron1_.environment_id
where
ecmenviron0_.server_id=?
...
select
ecmhistori0_.server_id as server3_1_,
ecmhistori0_.history_id as history1_1_,
ecmhistori0_.history_id as history1_8_0_,
ecmhistori0_.environment_id as environm2_8_0_,
ecmhistori0_.server_id as server3_8_0_,
ecmhistori0_.heap as heap8_0_,
ecmhistori0_.memory as memory8_0_,
ecmhistori0_.sessions as sessions8_0_,
ecmhistori0_.sessionsIdle as sessions7_8_0_,
ecmhistori0_.time as time8_0_
from
ecm.ecm_history ecmhistori0_
where
ecmhistori0_.server_id=?
order by
time DESC
Here the new mapping:
Code:
<hibernate-mapping>
<class name="com.basfits.ecm.core.server.EcmServer" table="ecm_server" catalog="ecm">
...
<bag order-by="time DESC"
name="ecmHistories" lazy="false" inverse="true">
<key>
<column name="server_id" not-null="true" />
</key>
<one-to-many class="com.basfits.ecm.core.history.EcmHistory" />
<filter name="envFilter" condition="environment_id = :env" />
</bag>
</class>
<filter-def name="envFilter">
<filter-param name="env" type="long"/>
</filter-def>
</hibernate-mapping>
And here is how I call the find method:
Code:
public EcmEnvironmentData findById(Long id){
getSession().enableFilter("envFilter").setParameter("env", id);
return (EcmEnvironmentData) getSession().get(EcmEnvironmentData.class, id);
}