Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Unexpected token in statement exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Unexpected token in statement exception

    Hello everybody,

    i have a problem with hibernate, spring and hsqldb. I try to get a list of Employees matching a companyId. I'll get this exception:

    Code:
    org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Could not execute query: encountered SQLException [Unexpected token: POSITION in statement [select employee0_.employeeId as employeeId, employee0_.name as name, employee0_.vorname as vorname, employee0_.position as position, employee0_.companyId as companyId from Employee employee0_ where (employee0_.companyId=? )]]; nested exception is java.sql.SQLException: Unexpected token: POSITION in statement [select employee0_.employeeId as employeeId, employee0_.name as name, employee0_.vorname as vorname, employee0_.position as position, employee0_.companyId as companyId from Employee employee0_ where (employee0_.companyId=? )]
    	org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:93)
    	org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:257)
    	org.springframework.orm.hibernate.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:240)
    	org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:227)
    	org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:319)
    	org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:633)
    	org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:621)
    	incore.vm.carmino.dao.hibernate.VmDaoHibernateImpl.getEmployeesForCompany(Unknown Source)
    	incore.vm.carmino.svc.dom.VmServiceDomImpl.getEmployeesForCompany(Unknown Source)
    	incore.vm.carmino.controller.ShowUIController.showEmployees(Unknown Source)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	java.lang.reflect.Method.invoke(Method.java:324)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:351)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:305)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:128)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
    	org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    My sourcecode is as follows:

    Code:
    public List getEmployeesForCompany(int companyId)
        {
            return _hibernateTemplate.find("from Employee employee " + 
                "where employee.company.companyId = ?" , new                 Integer(companyId),
                Hibernate.INTEGER);
        }
    This is my mapping file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping
        PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
        "http&#58;//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
        
    <hibernate-mapping>
        <class name="Employee" table="Employee">
            
            <id name="employeeId" column="employeeId" type="int">
                <generator class="native"/>
            </id>
               
            <property name="name"     column="name"     
                type="string" not-null="true"/>
            <property name="vorname"  column="vorname"  
                type="string" not-null="true"/>
            <property name="position" column="position" 
                type="string" not-null="true"/>
                
            <many-to-one name="company" column="companyId" 
                class="Company" not-null="true"/>
            
        </class>
    </hibernate-mapping>
    I don't know whats wrong. If i try to get all employees from the table with
    _hibernateTemplate.load(Employee.class) all works fine.

    Hope someone could help me. Thanks in advance!

    Torben

  • #2
    Problem nearly solved

    I know have renamed my column in the database from position to job and know all works fine. I think position is something special in the HSQLDB!?

    Thanks anyway guys

    bye

    Comment

    Working...
    X