0
<query..>
을 내 Car.hbm.xml에 넣으면 (Session) HibernateUtil.getSessionFactory().getCurrentSession();
에서 반환 된 세션이 null입니다. xml 매핑 파일에서 쿼리를 삭제하면 세션이 더 이상 null이 아닙니다. 왜이 오류가 발생합니까? 나는 그런 종류의 문제에 정말로 붙어있다. 최대 절전 명명 된 쿼리 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();
니켈 수소 ... 난 이미 방언 추가 : <속성 이름 = "방언"> org.hibernate.spatial.dialect.postgis.PostgisDialect 를하지만 MH .. 내 SQL 쿼리에 나는 객체를 지정해야 그때 돌려 보내고 싶다. 나는 차를 가지고 있고, 나는 모든 차에 일일 판매 합계를 요약하고 싶다. 이것은 1 대의 차와 관계가 없다. .. 그러나 나는 이것을위한 다른 실체를 가지고있다. .. 나는 차를 그 다음 돌려 놓을 수 없다. .. mhh. – krackmoe