如何使用create Query在hibernate中编写给定的查询

时间:2016-04-16 10:44:10

标签: hibernate

select tbl_LanguageData.Name As defaultLabel,
       IsNull((Select Top 1  LanguageInfo From tbl_Language_TranslationInfo 
               Where tbl_Language_TranslationInfo.Languageid = 48 
               And tbl_Language_TranslationInfo.LanguageDataId = tbl_LanguageData.LanguageDataId), 
       tbl_LanguageData.Name) As localLang
from tbl_UILabels, tbl_LanguageData
Where tbl_UILabels.LanguageDataId = tbl_LanguageData.LanguageDataId 
  And menuid = 10100

1 个答案:

答案 0 :(得分:0)

如果已经定义了持久性单元(存储库META-INF中的文件persistence.xml),则可以使用实体管理器和createNativeQuery方法

//declare the entity manager

EntityManager em = Persistence.createEntityManagerFactory("name of your persistence unit").createEntityManager();

String request = "your request";

Result result = em.createNativeQuery(request,Result.class).getResultList();