2011-03-06 26 views
0


是否可以通过点获取HQL结果。
例如:HQL - 从DOT分隔符中获得选择结果

select Employee.name as 'Employee.name' 

我知道,MySQL允许,是否有杉木,在休眠的支持。
这是我得到的exeption:中

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 “”不能为我工作。
谢谢

回答

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