0

如上所述,我遇到了上面提到的异常。

你能帮忙吗?谢谢


我查看了各种指南/教程,但它们并没有真正告诉您运行此类示例所需的映射是什么。或者我看到的示例实际上并没有涉及检索数据的任何内容。它主要是关于插入/更新和删除。

jboss 文档中的一个示例(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;
    }
}

我的网址类

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;
    }
}
4

1 回答 1

0

如果您尝试进行右连接,请删除 (+) 并尝试

sessionFactory.getCurrentSession().createQuery("from Staff staff right join Url url where (staff.id = url.id)");
于 2012-12-11T08:42:14.983 回答