我正在使用hibernate和REST服务。查看 REST SERVICE 下面的代码,在这种情况下如何使用HQL语句(Hibernate查询)提取content_id?
例如我的尝试......
<query cache-mode="get" cacheable="true" flush-mode="auto"
name="Languages.getLanguageById" read-only="true">
select languageId as id,displayName as name from Languages where id=<query-param name="languageId" type="java.lang.Long"/>
</query>
// REST服务
@Path("{resource}/getLanguageById")
@GET
@Produces(MediaType.TEXT_XML)
public String getLanguageById(@PathParam("resource") String id,
@QueryParam("content-id")String content_id)
{
........
.......
}
// Hibernate XML
<hibernate-mapping>
<class catalog="CONTENT" name="test.db.com.Languages" table="languages">
<id name="languageId" type="java.lang.Long">
<column name="languageId"/>
<generator class="identity"/>
</id>
<property generated="never" lazy="false" name="language" type="string">
<column length="50" name="language" not-null="true"/>
</property>
<property generated="never" lazy="false" name="displayName" type="string">
<column length="50" name="displayName" not-null="true"/>
</property>
</class>
</hibernate-mapping>
答案 0 :(得分:0)
没关系我找到了替代解决方案
public static List listObject1(String queryname,Long content_id) {
String query = "select languageId as id,displayName as name from Languages where id =:query_id";
Transaction tx = null;
Session session = SessionFactoryUtil.getInstance().openSession();
Query myquery = session.createQuery(query);
myquery.setParameter("query_id",content_id);
......
.......more code
}