0
如果我把<query..>
放在我的Car.hbm.xml中,我從(Session) HibernateUtil.getSessionFactory().getCurrentSession();
返回的會話爲空,如果我從我的xml映射文件中刪除查詢,那麼會話不再爲空。 爲什麼我得到這個錯誤?我真的被這種問題困住了。休眠命名查詢xml映射
我得到這個XML映射:
<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>
而這正是我要調用的命名查詢:
Transaction transaction = null;
int amount = 0;
try{
Session session = (Session) HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.beginTransaction();
amount = (Integer)session.getNamedQuery("dailysales").uniqueResult();
MH ......我已經加入這個方言:<屬性名=「方言」> org.hibernate.spatial.dialect.postgis.PostgisDialect 但MH ..在我的sql查詢我必須指定哪個對象我然後想要返回。 我有車,我想總結一下所有車的日銷售額。 這與一輛車無關..但我沒有另一個實體...我不能返回一輛車,然後.. mhh .. – krackmoe 2013-02-18 19:10:28