Announcement Announcement Module
Collapse
No announcement yet.
Spring + Hibernate ORA-00936: missing expression Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + Hibernate ORA-00936: missing expression

    Hi,

    I 've got some problems when using spring with hibernate and Oracle.

    I receceive this error when I execute a select on a single table.

    Code:
    11:08:13,855 INFO  [SQLErrorCodesFactory] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
    11:08:13,871 INFO  [STDOUT] Hibernate: select  from
    11:08:13,887 WARN  [JDBCExceptionReporter] SQL Error: 936, SQLState: 42000
    11:08:13,887 ERROR [JDBCExceptionReporter] ORA-00936: missing expression
    
    11:08:13,887 WARN  [JDBCExceptionReporter] SQL Error: 936, SQLState: 42000
    11:08:13,887 ERROR [JDBCExceptionReporter] ORA-00936: missing expression
    
    11:08:13,887 ERROR [JDBCExceptionReporter] Could not execute query
    java.sql.SQLException: ORA-00936: missing expression
    
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    	at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    	at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
    	at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
    	at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
    	at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
    	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
    	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
    	at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
    	at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
    	at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
    	at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
    	at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
    	at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
    	at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
    	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
    	at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
    	at org.springframework.orm.hibernate.HibernateTemplate$19.doInHibernate(HibernateTemplate.java:647)
    	at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:314)
    	at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:633)
    	at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:612)
    	at be.brail.tutorial.dao.db.implementations.hibernate.EmployeeDAOImpl.listOfEmployees(EmployeeDAOImpl.java:25)
    	at be.brail.tutorial.services.implementations.EmployeeServiceImpl.ListOfEmployee(EmployeeServiceImpl.java:31)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:288)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
    	at $Proxy65.ListOfEmployee(Unknown Source)
    	at be.brail.tutorial.struts.actions.EmployeeListAction.execute(EmployeeListAction.java:44)
    	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
    	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:147)
    	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:53)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:743)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    	at java.lang.Thread.run(Thread.java:595)
    11:08:13,902 WARN  [RequestProcessor] Unhandled Exception thrown: class org.springframework.jdbc.BadSqlGrammarException
    11:08:13,902 ERROR [StandardWrapper[/Employee-tutorial:action]] Servlet.service() for servlet action threw exception
    org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: Could not execute query; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-00936: missing expression
    
    java.sql.SQLException: ORA-00936: missing expression
    
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    	at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    	at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
    	at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
    	at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
    	at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
    	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
    	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
    	at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
    	at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
    	at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
    	at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
    	at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
    	at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
    	at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
    	at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
    	at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
    	at org.springframework.orm.hibernate.HibernateTemplate$19.doInHibernate(HibernateTemplate.java:647)
    	at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:314)
    	at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:633)
    	at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:612)
    	at be.brail.tutorial.dao.db.implementations.hibernate.EmployeeDAOImpl.listOfEmployees(EmployeeDAOImpl.java:25)
    	at be.brail.tutorial.services.implementations.EmployeeServiceImpl.ListOfEmployee(EmployeeServiceImpl.java:31)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:288)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
    	at $Proxy65.ListOfEmployee(Unknown Source)
    	at be.brail.tutorial.struts.actions.EmployeeListAction.execute(EmployeeListAction.java:44)
    	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
    	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:147)
    	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:53)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:743)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    	at java.lang.Thread.run(Thread.java:595)
    My environment :

    Win XP
    JBoss 4.0.2 RC1
    Spring 1.2.1
    Hibernate 2.1

    Here is my configuration file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>	
    
    	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" singleton="true">
    		<property name="jndiName">
    			<value>java&#58;jdbc/employee</value>
    		</property>
    	</bean>
    
    
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    
    		<property name="dataSource">
    			<ref bean="dataSource"/>
    		</property>
    
    		<property name="mappingResources">
    			<list>
    				<value>be/brail/tutorial/model/Employee.hbm.xml</value>
    				<value>be/brail/tutorial/model/Vehicle.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.statement_cache.size">25</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.query.substitutions">true 1,false 0,yes 'Y',no 'N'</prop>
    				<prop key="hibernate.query.imports">net.sf.hibernate.test,net.sf.hibernate.eg</prop>
    				<prop key="hibernate.proxool.pool_alias">pool1</prop>
    				<prop key="hibernate.jdbc.user_streams_for_binary">true</prop>
    				<prop key="hibernate.jdbc.batch_size">0</prop>
    				<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
    				<prop key="hibernate.connection.pool_size">1</prop>
    				<prop key="hibernate.cglib.user_reflection_optimizer">true</prop>
    				<prop key="hibernate.use_outer_join">true</prop>
    				<prop key="hibernate.cache.use_query_cache">false</prop>
    				<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</prop>				
    			</props>
    		</property>
    	</bean>
    
    	<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory"/>
    		</property>
    	</bean>
    
    
    <!--  DAO SECTION -->
    
    	<bean id="baseDAO" class="be.brail.tutorial.dao.db.implementations.hibernate.BaseDAOImpl">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory"/>
    		</property> 
        </bean>
    
    	<bean id="employeeDAO" class="be.brail.tutorial.dao.db.implementations.hibernate.EmployeeDAOImpl">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory"/>
    		</property> 
        </bean>
    
    	<bean id="vehicleDAO" class="be.brail.tutorial.dao.db.implementations.hibernate.VehicleDAOImpl">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory"/>
    		</property> 
        </bean>
    
    
    
    	<!--  SERVICE INITIALISATION -->
    
    	<bean id="txProxyTemplate" lazy-init="true"
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
       	
       	 	<property name="transactionManager">
       	 		<ref local="transactionManager"/>
       	 	</property>
        
        	<property name="transactionAttributes">
    	      	<props>
        	    	<prop key="*">PROPAGATION_REQUIRED</prop>
          		</props>
        	</property>
      	</bean>
    
    
    	<bean id="employeeService" parent="txProxyTemplate">
    		<property name="target">
    			<bean class="be.brail.tutorial.services.implementations.EmployeeServiceImpl">
    				<property name="employeeDAO">
    				 	<ref bean="employeeDAO"/>
    				</property>
    			</bean>
    			
    		</property>
    	
    	</bean>
    
    
    
    	<bean id="vehicleService" parent="txProxyTemplate">
    		<property name="target">
    			<bean class="be.brail.tutorial.services.implementations.VehicleServiceImpl">
    				<property name="vehicleDAO">
    				 	<ref bean="vehicleDAO"/>
    				</property>
    			</bean>
    			
    		</property>
    	
    	</bean>
    
    
    
    </beans>
    The error occurs when I use the service employeeService and the method ListOfEmployee(). It's only at runtime that the problem occurs.
    When the server start and the project is loaded in the server all seems good.

    The bean code:

    Code:
    package be.brail.tutorial.model;
    
    import java.io.Serializable;
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
    
    /**
     * <p>Title&#58; </p>
     * <p>Description&#58; </p>
     * <p>Copyright&#58; Copyright &#40;c&#41; 2005</p>
     * <p>Company&#58; SNCB/NMBS</p>
     * <p>Creation time &#58; 06-Jun-2005 - 16&#58;46&#58;30</p>
     * @author Geraerts François
     * @version 1.0
     * 
     * @hibernate.class table = "TUT_EMPLOYEE"
     * 
     * Represents a Employee.
     */
    public class Employee implements Serializable
    &#123;
    
        private String employeeId;
        private String name;
        private String firstName;
        private String sex;
        private Date birthDate;
        private String dept;
        
        
        private Set vehicles = new HashSet&#40;&#41;;
        
        /**
         * @hibernate.property column = "BirthDate" type = "string"
         * @return Returns the birthDate.
         */
        public Date getBirthDate&#40;&#41; &#123;
            return birthDate;
        &#125;
        /**
         * @param birthDate The birthDate to set.
         */
        public void setBirthDate&#40;Date birthDate&#41; &#123;
            this.birthDate = birthDate;
        &#125;
        /**
         * @hibernate.property column = "Dept" type = "date"
         * @return Returns the dept.
         */
        public String getDept&#40;&#41; &#123;
            return dept;
        &#125;
        /**
         * @param dept The dept to set.
         */
        public void setDept&#40;String dept&#41; &#123;
            this.dept = dept;
        &#125;
        /**
         * @hibernate.id generator-class = "assigned" column = "EMPLOYEE_ID"
         * @return Returns the employeeId.
         */
        public String getEmployeeId&#40;&#41; &#123;
            return employeeId;
        &#125;
        /**
         * @param employeeId The employeeId to set.
         */
        public void setEmployeeId&#40;String employeeId&#41; &#123;
            this.employeeId = employeeId;
        &#125;
        /**
         * @hibernate.property column = "FirstName" type = "string"
         * @return Returns the firstName.
         */
        public String getFirstName&#40;&#41; &#123;
            return firstName;
        &#125;
        /**
         * @param firstName The firstName to set.
         */
        public void setFirstName&#40;String firstName&#41; &#123;
            this.firstName = firstName;
        &#125;
        /**
         * @hibernate.property column = "Name" type = "string"
         * @return Returns the name.
         */
        public String getName&#40;&#41; &#123;
            return name;
        &#125;
        /**
         * @param name The name to set.
         */
        public void setName&#40;String name&#41; &#123;
            this.name = name;
        &#125;
        /**
         * @hibernate.property column = "Sex" type = "string"
         * @return Returns the sex.
         */
        public String getSex&#40;&#41; &#123;
            return sex;
        &#125;
        /**
         * @param sex The sex to set.
         */
        public void setSex&#40;String sex&#41; &#123;
            this.sex = sex;
        &#125;
    
    
        /**
         * @hibernate.set table = "TUT_VEHICLE" cascade = "none"
         * @hibernate.collection-key column = "EMPLOYEE_ID"
         * @hibernate.collection-one-to-many class = "be.brail.tutorial.model.Vehicle"
         * @return Returns the vehicles.
         */
        public Set getVehicles&#40;&#41; &#123;
            return vehicles;
        &#125;
        /**
         * @param vehicles The vehicles to set.
         */
        public void setVehicles&#40;Set vehicles&#41; &#123;
            this.vehicles = vehicles;
        &#125;
    &#125;

    The dao implementation code :

    Code:
    package be.brail.tutorial.dao.db.implementations.hibernate;
    
    import java.util.List;
    
    import org.springframework.orm.ObjectRetrievalFailureException;
    
    import be.brail.tutorial.dao.db.interfaces.EmployeeDAO;
    import be.brail.tutorial.model.Employee;
    
    /**
     * @author Geraerts François
     * Creation Date &#58; 09-juin-2005
     * 
     * EmployeeDAOImpl.java
     */
    public class EmployeeDAOImpl extends BaseDAOImpl implements EmployeeDAO &#123;
    
        /* &#40;non-Javadoc&#41;
         * @see be.brail.tutorial.dao.db.interfaces.EmployeeDAO#listOfEmployees&#40;&#41;
         */
        public List listOfEmployees&#40;&#41; 
        &#123;
    
            log.warn&#40;"listOfEmployees"&#41;;
            List result = getHibernateTemplate&#40;&#41;.find&#40;"FROM TUT_EMPLOYEE"&#41;;
            
            if &#40;result.isEmpty&#40;&#41;&#41; 
            &#123;
                throw new ObjectRetrievalFailureException&#40;Employee.class,null&#41;;
            &#125;
            else
            &#123;
                return result;
            &#125;
        &#125;
    
        /* &#40;non-Javadoc&#41;
         * @see be.brail.tutorial.dao.db.interfaces.EmployeeDAO#findAnEmployee&#40;java.lang.String&#41;
         */
        public Employee findAnEmployee&#40;String employeeId&#41; 
        &#123;
            
            List result = getHibernateTemplate&#40;&#41;.find&#40;"FROM TUT_EMPLOYEE WHERE EMPLOYEE_ID = ?",employeeId&#41;;
            
            if &#40;result.isEmpty&#40;&#41;&#41; 
            &#123;
                throw new ObjectRetrievalFailureException&#40;Employee.class,employeeId&#41;;
            &#125;
            else
            &#123;
                return &#40;Employee&#41;result.get&#40;0&#41;;
            &#125;
        &#125;
    
    &#125;
    and the base dao code :
    Code:
    package be.brail.tutorial.dao.db.implementations.hibernate;
    
    import java.io.Serializable;
    import java.util.List;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.orm.ObjectRetrievalFailureException;
    import org.springframework.orm.hibernate.support.HibernateDaoSupport;
    
    import be.brail.tutorial.dao.db.interfaces.BaseDAO;
    
    /**
     * This class serves as the Base class for all other DAOs - namely to hold
     * common methods that they might all use. Can be used for standard CRUD
     * operations.</p>
     *
     *
     */
    public class BaseDAOImpl extends HibernateDaoSupport implements BaseDAO &#123;
        protected final Log log = LogFactory.getLog&#40;getClass&#40;&#41;&#41;;
    
        /**
         * @see be.brail.a629.dao.db.interfaces.BaseDAO#saveObject&#40;java.lang.Object&#41;
         */
        public void saveObject&#40;Object o&#41; &#123;
            getHibernateTemplate&#40;&#41;.saveOrUpdate&#40;o&#41;;
        &#125;
    
        /**
         * @see be.brail.a629.dao.db.interfaces.BaseDAO#getObject&#40;java.lang.Class, java.io.Serializable&#41;
         */
        public Object getObject&#40;Class clazz, Serializable id&#41; &#123;
            Object o = getHibernateTemplate&#40;&#41;.get&#40;clazz, id&#41;;
    
            if &#40;o == null&#41; &#123;
                throw new ObjectRetrievalFailureException&#40;clazz, id&#41;;
            &#125;
    
            return o;
        &#125;
    
        /**
         * @see be.brail.a629.dao.db.interfaces.BaseDAO#getObjects&#40;java.lang.Class&#41;
         */
        public List getObjects&#40;Class clazz&#41; &#123;
            return getHibernateTemplate&#40;&#41;.loadAll&#40;clazz&#41;;
        &#125;
    
        /**
         * @see be.brail.a629.dao.db.interfaces.BaseDAO#removeObject&#40;java.lang.Class, java.io.Serializable&#41;
         */
        public void removeObject&#40;Class clazz, Serializable id&#41; &#123;
            getHibernateTemplate&#40;&#41;.delete&#40;getObject&#40;clazz, id&#41;&#41;;
        &#125;
    &#125;
    When i look at the error, it's seems that the hibernate definition is "not load" or is not in the context. The corresponding sql generate is "
    select from. But when I look in the start of the server the context seems well initalised. It 's seem to be an configuration error but i don't have any idea.


    To be complete the hibernate config file and the startup of the server:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
        "http&#58;//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
    
    <hibernate-mapping
    >
        <class
            name="be.brail.tutorial.model.Employee"
            table="TUT_EMPLOYEE"
        >
    
            <id
                name="employeeId"
                column="EMPLOYEE_ID"
                type="java.lang.String"
            >
                <generator class="assigned">
                  <!--  
                      To add non XDoclet generator parameters, create a file named 
                      hibernate-generator-params-Employee.xml 
                      containing the additional parameters and place it in your merge dir. 
                  --> 
                </generator>
            </id>
    
            <property
                name="birthDate"
                type="string"
                update="true"
                insert="true"
                column="BirthDate"
            />
    
            <property
                name="dept"
                type="date"
                update="true"
                insert="true"
                column="Dept"
            />
    
            <property
                name="firstName"
                type="string"
                update="true"
                insert="true"
                column="FirstName"
            />
    
            <property
                name="name"
                type="string"
                update="true"
                insert="true"
                column="Name"
            />
    
            <property
                name="sex"
                type="string"
                update="true"
                insert="true"
                column="Sex"
            />
    
            <set
                name="vehicles"
                table="TUT_VEHICLE"
                lazy="false"
                cascade="none"
                sort="unsorted"
            >
    
                <key
                    column="EMPLOYEE_ID"
                >
                </key>
    
                <one-to-many
                      class="be.brail.tutorial.model.Vehicle"
                />
    
            </set>
    
            <!--
                To add non XDoclet property mappings, create a file named
                    hibernate-properties-Employee.xml
                containing the additional properties and place it in your merge dir.
            -->
    
        </class>
    
    </hibernate-mapping>
    and the startup:

    Code:
    13&#58;52&#58;02,366 INFO  &#91;TomcatDeployer&#93; undeploy, ctxPath=/Employee-tutorial, warUrl=file&#58;/C&#58;/jboss-4.0.2RC1/server/default/tmp/deploy/tmp2754Employee-ear.ear-contents/Employee-war-exp.war/
    13&#58;52&#58;02,553 INFO  &#91;&#91;/Employee-tutorial&#93;&#93; Closing WebApplicationContext of Struts ActionServlet 'action', module ''
    13&#58;52&#58;02,553 INFO  &#91;XmlWebApplicationContext&#93; Closing application context &#91;WebApplicationContext for namespace 'action-servlet'&#93;
    13&#58;52&#58;03,054 INFO  &#91;DefaultListableBeanFactory&#93; Destroying singletons in factory &#123;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;dataSource,sessionFactory,transactionManager,baseDAO,employeeDAO,vehicleDAO,txProxyTemplate,employeeService,vehicleService&#93;; root of BeanFactory hierarchy&#125;
    13&#58;52&#58;03,054 INFO  &#91;LocalSessionFactoryBean&#93; Closing Hibernate SessionFactory
    13&#58;52&#58;03,054 INFO  &#91;SessionFactoryImpl&#93; closing
    13&#58;52&#58;04,475 WARN  &#91;DeploymentInfo&#93; Could not delete file&#58;/C&#58;/jboss-4.0.2RC1/server/default/tmp/deploy/tmp2754Employee-ear.ear-contents/Employee-war-exp.war/ restart will delete it
    13&#58;52&#58;04,475 INFO  &#91;EARDeployer&#93; Undeploying J2EE application, destroy step&#58; file&#58;/C&#58;/jboss-4.0.2RC1/server/default/deploy/Employee-ear.ear
    13&#58;52&#58;04,522 WARN  &#91;DeploymentInfo&#93; Could not delete file&#58;/C&#58;/jboss-4.0.2RC1/server/default/tmp/deploy/tmp2754Employee-ear.ear restart will delete it
    13&#58;52&#58;04,647 INFO  &#91;EARDeployer&#93; Init J2EE application&#58; file&#58;/C&#58;/jboss-4.0.2RC1/server/default/deploy/Employee-ear.ear
    13&#58;52&#58;06,491 INFO  &#91;TomcatDeployer&#93; deploy, ctxPath=/Employee-tutorial, warUrl=file&#58;/C&#58;/jboss-4.0.2RC1/server/default/tmp/deploy/tmp2755Employee-ear.ear-contents/Employee-war-exp.war/
    13&#58;52&#58;11,507 INFO  &#91;PropertyMessageResources&#93; Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
    13&#58;52&#58;11,507 INFO  &#91;PropertyMessageResources&#93; Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
    13&#58;52&#58;12,335 INFO  &#91;PropertyMessageResources&#93; Initializing, config='be.brail.tutorial.struts.ApplicationResources', returnNull=true
    13&#58;52&#58;12,476 INFO  &#91;ContextLoaderPlugIn&#93; ContextLoaderPlugIn for Struts ActionServlet 'action, module ''&#58; initialization started
    13&#58;52&#58;12,476 INFO  &#91;&#91;/Employee-tutorial&#93;&#93; Initializing WebApplicationContext for Struts ActionServlet 'action', module ''
    13&#58;52&#58;12,741 INFO  &#91;XmlBeanDefinitionReader&#93; Loading XML bean definitions from ServletContext resource &#91;/WEB-INF/applicationContext.xml&#93;
    13&#58;52&#58;13,179 INFO  &#91;XmlWebApplicationContext&#93; Bean factory for application context &#91;WebApplicationContext for namespace 'action-servlet'&#93;&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;dataSource,sessionFactory,transactionManager,baseDAO,employeeDAO,vehicleDAO,txProxyTemplate,employeeService,vehicleService&#93;; root of BeanFactory hierarchy
    13&#58;52&#58;13,226 INFO  &#91;XmlWebApplicationContext&#93; 9 beans defined in application context &#91;WebApplicationContext for namespace 'action-servlet'&#93;
    13&#58;52&#58;13,257 INFO  &#91;CollectionFactory&#93; JDK 1.4+ collections available
    13&#58;52&#58;13,288 INFO  &#91;CollectionFactory&#93; Commons Collections 3.x available
    13&#58;52&#58;13,304 INFO  &#91;XmlWebApplicationContext&#93; Unable to locate MessageSource with name 'messageSource'&#58; using default &#91;[email protected]07&#93;
    13&#58;52&#58;13,304 INFO  &#91;XmlWebApplicationContext&#93; Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster'&#58; using default &#91;org.springframework.context.event.SimpleApplicationEventMulticaster@13fe849&#93;
    13&#58;52&#58;13,320 INFO  &#91;UiApplicationContextUtils&#93; No ThemeSource found for &#91;WebApplicationContext for namespace 'action-servlet'&#93;&#58; using ResourceBundleThemeSource
    13&#58;52&#58;13,335 INFO  &#91;DefaultListableBeanFactory&#93; Pre-instantiating singletons in factory &#91;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;dataSource,sessionFactory,transactionManager,baseDAO,employeeDAO,vehicleDAO,txProxyTemplate,employeeService,vehicleService&#93;; root of BeanFactory hierarchy&#93;
    13&#58;52&#58;13,335 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'dataSource'
    13&#58;52&#58;13,507 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'sessionFactory'
    13&#58;52&#58;13,648 INFO  &#91;Binder&#93; Mapping class&#58; be.brail.tutorial.model.Employee -> TUT_EMPLOYEE
    13&#58;52&#58;13,679 INFO  &#91;Binder&#93; Mapping class&#58; be.brail.tutorial.model.Vehicle -> TUT_VEHICLE
    13&#58;52&#58;13,679 INFO  &#91;LocalSessionFactoryBean&#93; Building new Hibernate SessionFactory
    13&#58;52&#58;13,679 INFO  &#91;Configuration&#93; processing one-to-many association mappings
    13&#58;52&#58;13,679 INFO  &#91;Binder&#93; Mapping collection&#58; be.brail.tutorial.model.Employee.vehicles -> TUT_VEHICLE
    13&#58;52&#58;13,679 INFO  &#91;Configuration&#93; processing one-to-one association property references
    13&#58;52&#58;13,679 INFO  &#91;Configuration&#93; processing foreign key constraints
    13&#58;52&#58;13,679 INFO  &#91;Dialect&#93; Using dialect&#58; net.sf.hibernate.dialect.Oracle9Dialect
    13&#58;52&#58;13,679 INFO  &#91;SettingsFactory&#93; Use outer join fetching&#58; true
    13&#58;52&#58;13,679 INFO  &#91;ConnectionProviderFactory&#93; Initializing connection provider&#58; org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
    13&#58;52&#58;13,679 INFO  &#91;TransactionManagerLookupFactory&#93; No TransactionManagerLookup configured &#40;in JTA environment, use of process level read-write cache is not recommended&#41;
    13&#58;52&#58;13,960 INFO  &#91;SettingsFactory&#93; Use scrollable result sets&#58; true
    13&#58;52&#58;13,960 INFO  &#91;SettingsFactory&#93; Use JDBC3 getGeneratedKeys&#40;&#41;&#58; false
    13&#58;52&#58;13,960 INFO  &#91;SettingsFactory&#93; Optimize cache for minimal puts&#58; false
    13&#58;52&#58;13,960 INFO  &#91;SettingsFactory&#93; echoing all SQL to stdout
    13&#58;52&#58;13,960 INFO  &#91;SettingsFactory&#93; Query language substitutions&#58; &#123;no='N', true=1, yes='Y', false=0&#125;
    13&#58;52&#58;13,960 INFO  &#91;SettingsFactory&#93; cache provider&#58; net.sf.ehcache.hibernate.Provider
    13&#58;52&#58;13,960 INFO  &#91;Configuration&#93; instantiating and configuring caches
    13&#58;52&#58;13,960 INFO  &#91;SessionFactoryImpl&#93; building session factory
    13&#58;52&#58;14,117 INFO  &#91;SessionFactoryObjectFactory&#93; Not binding factory to JNDI, no JNDI name configured
    13&#58;52&#58;14,117 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'transactionManager'
    13&#58;52&#58;14,195 INFO  &#91;HibernateTransactionManager&#93; Using DataSource &#91;org.jboss.resource.adapter.jdbc.WrapperDataSource@f04dae&#93; of Hibernate SessionFactory for HibernateTransactionManager
    13&#58;52&#58;14,210 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'baseDAO'
    13&#58;52&#58;14,242 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'employeeDAO'
    13&#58;52&#58;14,257 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'vehicleDAO'
    13&#58;52&#58;14,257 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'employeeService'
    13&#58;52&#58;14,273 INFO  &#91;DefaultAopProxyFactory&#93; CGLIB2 available&#58; proxyTargetClass feature enabled
    13&#58;52&#58;14,554 INFO  &#91;DefaultListableBeanFactory&#93; Creating shared instance of singleton bean 'vehicleService'
    13&#58;52&#58;14,585 INFO  &#91;ContextLoaderPlugIn&#93; Using context class 'org.springframework.web.context.support.XmlWebApplicationContext' for servlet 'action'
    13&#58;52&#58;14,585 INFO  &#91;ContextLoaderPlugIn&#93; ContextLoaderPlugIn for Struts ActionServlet 'action', module ''&#58; initialization completed in 2109 ms
    13&#58;52&#58;14,710 INFO  &#91;EARDeployer&#93; Started J2EE application&#58; file&#58;/C&#58;/jboss-4.0.2RC1/server/default/deploy/Employee-ear.ear
    Thanks for advice or any suggestion about this problem.

    Hugh.

  • #2
    The error is in the dao implementation.
    The select in the method find was previously done on the db table and not on the bean.

    The correct code is:

    Code:
        public List listOfEmployees&#40;&#41; 
        &#123;
    
            log.warn&#40;"listOfEmployees"&#41;;
            List result = getHibernateTemplate&#40;&#41;.find&#40;"FROM Employee e"&#41;;
            
            if &#40;result.isEmpty&#40;&#41;&#41; 
            &#123;
                throw new ObjectRetrievalFailureException&#40;Employee.class,null&#41;;
            &#125;
            else
            &#123;
                return result;
            &#125;
        &#125;
    Hugh.

    Comment

    Working...
    X