本文介绍了JPA是否具有与Hibernate SQLQuery.addScalar()等效的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
session.createSQLQuery(SELECT * FROM CATS)
.addScalar(ID,Hibernate.LONG)
.addScalar(NAME,Hibernate.STRING)
.addScalar(BIRTHDATE,Hibernate.DATE)
在新项目中,我们使用Hibernate EntityManager(JPA实现)。
是否有与那些对addScalar()的调用等价的?我是否需要像以前那样指定返回列的类型?
例如,如果我不使用addScalar将SQL查询结果缓存起来吗?
解决方案
这篇文章
似乎提供了一个类似的,更短的解决方案,它似乎适用于我:
查询q2 = em.createNativeQuery(select sc_cur_code,sc_amount from sector_costs);
q2.unwrap(SQLQuery.class).addScalar(sc_cur_code,StringType.INSTANCE);
My old Hibernate-only code uses something like
session.createSQLQuery("SELECT * FROM CATS")
.addScalar("ID", Hibernate.LONG)
.addScalar("NAME", Hibernate.STRING)
.addScalar("BIRTHDATE", Hibernate.DATE)
In the new project we use Hibernate EntityManager (the JPA implementation).
Is there an equivalent to those calls to addScalar()? Do I need to specify the types of the returned columns as I did before?
For example, if I don't use addScalar will the SQL query results be cached?
解决方案
The post Hibernate native query - char(3) column
seems to offer a similar, shorter solution, which appears to work for me:
Query q2 = em.createNativeQuery("select sc_cur_code, sc_amount from sector_costs");
q2.unwrap(SQLQuery.class).addScalar("sc_cur_code", StringType.INSTANCE);
这篇关于JPA是否具有与Hibernate SQLQuery.addScalar()等效的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!