0
如上所述,我得到上述異常。越來越org.hibernate.hql.internal.ast.QuerySyntaxException錯誤
你能幫忙嗎?感謝
我已經看了各種指南/教程和他們真的不告訴你什麼是運行這樣的例子所需要的映射。或者我見過的例子並沒有涉及檢索數據的任何事情。這主要是關於插入/更新和刪除。
從JBoss DOC(http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch16.html)
select foo
from Foo foo, Bar bar
where foo.startDate = bar.date
此示例是我的HQL:
sessionFactory.getCurrentSession().createQuery("from Staff staff, Url url where (staff.id = url.id (+))");
這是我的XML映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.flinders.staffdirectory.models.database.Staff" table="teld_summary">
<id name="id" column="telsumm_id" type="string" />
<property name="title" column="telsumm_name_title" type="string" />
<property name="firstname" column="telsumm_preferred_name" type="string" />
<property name="surname" column="telsumm_surname" type="string" />
<one-to-one name="url" class="org.flinders.staffdirectory.models.database.Url" />
</class>
<class name="org.flinders.staffdirectory.models.database.Url" table="teld_urls">
<id name="id" column="telurl_id">
<generator class="foreign">
<param name="property">staff</param>
</generator>
</id>
<one-to-one name="staff" class="org.flinders.staffdirectory.models.database.Staff" constrained="true" />
<property name="url" column="url" />
</class>
</hibernate-mapping>
我的錯誤
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token:) near line 1, column 142 [from org.flinders.staffdirectory.models.database.Staff staff, org.flinders.staffdirectory.models.database.Url url where (staff.id = url.id (+)) and (staff.surnameSearch like 'A%') order by surname, firstname]
org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:276)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735)
org.flinders.staffdirectory.dao.StaffDAOImpl.searchForStaff(StaffDAOImpl.java:49)
org.flinders.staffdirectory.services.SearchServiceImpl.searchForStaff(SearchServiceImpl.java:26)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy13.searchForStaff(Unknown Source)
org.flinders.staffdirectory.controllers.SearchController.showSearchResults(SearchController.java:33)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
我的員工類
package org.flinders.staffdirectory.models.database;
import java.util.Date;
import org.flinders.staffdirectory.models.database.Url;
public class Staff {
private String id;
private String title;
private String firstname;
private String surname;
private Url url;
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public Url getUrl() {
return url;
}
public void setUrl(Url url) {
this.url = url;
}
}
我的URL類
package org.flinders.staffdirectory.models.database;
import org.flinders.staffdirectory.models.database.Staff;
public class Url {
private String id;
private String url;
private Staff staff;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Staff getStaff() {
return staff;
}
public void setStaff(Staff staff) {
this.staff = staff;
}
}
爲什麼你在查詢中使用'(+)'? –
在你的錯誤'org.hibernate.hql.internal.ast.QuerySyntaxException:意外的標記:)在第1行,第142列'這表明你的查詢中有(+)'有問題。 –
查詢你的異常和查詢你上面寫的是不一樣的。哪一個是正確的? –