是否可以通过点获得HQL结果
例如:
select Employee.name as 'Employee.name'
我知道mysql允许,在休眠中是否有任何支持fir 这是我得到的例外:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: . near line 1, column 42 [SELECT Affiliate.affiliateId as Affiliate.affiliateId , parent.userName as parent_userName , Affiliate.userName as Affiliate_userName , Affiliate.email as Affiliate_email , parent.affiliateId as parent_affiliateId , employee.firstName as employee_firstName , Affiliate.name as Affiliate_name FROM com.affiliates.hibernate.Affiliate Affiliate INNER JOIN Affiliate.employee as employee INNER JOIN Affiliate.parent as parent WHERE 1=1 AND Affiliate.employee='1']
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
由于架构问题,“_”instad为“。”不能为我工作。
感谢
答案 0 :(得分:1)
我不确定我是否正确理解了你的问题。您正在考虑编写查询。 Hibernate支持其内部语言HQL。说实话,我更喜欢使用JPA和hibernate作为JPA实现。在这种情况下,您必须使用Criteria Api或JPA query language撰写查询。查询语言与NamedQueries一起使用非常方便。因此,如果您使用的是HQL或JPA,最简单的方法是选择具有某个名称的对象
SELECT e FROM Employee e WHERE p.name = ?1
另一种可能是使用NativeQuery,这里是example。