0

我正在使用休眠和 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>

//休息服务

@Path("{resource}/getLanguageById")

@GET
@Produces(MediaType.TEXT_XML)  
public String getLanguageById(@PathParam("resource") String id, 
                              @QueryParam("content-id")String content_id)
{

            ........
            .......

}

//休眠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>
4

1 回答 1

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
    }
于 2012-06-06T18:36:53.263 回答