If i put a <query..>
in my Car.hbm.xml the session i get returned from (Session) HibernateUtil.getSessionFactory().getCurrentSession();
is null, if i delete the query from my xml mapping file the session is not null anymore.
Why do i get this error? I am really stuck with that kind of problem.
I got this xml mapping:
<hibernate-mapping package="at.opendata.entitys">
<class name="Car" table="Cars">
<id name="id" column="car_Id">
<generator class="increment"/>
</id>
<set name="carDetails" table="Cardetail" cascade="all" lazy="false" fetch="select" >
<key column="car_id" not-null="true"/>
<one-to-many class="CarDetail" />
</set>
<property name="name" not-null="true"/>
<property name="vin" not-null="true"/>
</class>
<query name="dailysales">
<![CDATA[select sum(date_part('minute', age(cd.gone, cd.back))) from Car as c left join c.carDetails as cd where cd.gone is not null and cd.back is not null]]>
</query>
</hibernate-mapping>
And this is where i want to call the named query:
Transaction transaction = null;
int amount = 0;
try{
Session session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.beginTransaction();
amount = (Integer)session.getNamedQuery("dailysales").uniqueResult();