2

Its a project using Spring4 and hibernate4 ,I have problem with running the pronect as it returns could not extract ResultSet I have crearted the database and have connected as usual.But it returns error.How can i solve it.

HomeController code

@Controller
public class HomeController {

@Autowired
private UserDao userDAO;

@RequestMapping(value="/")
public ModelAndView home(){
List<User> listUser=userDAO.list();
ModelAndView model=new ModelAndView("home");
model.addObject("userList",listUser);
return model;   
}

UserDAOImplementation Code

public class UserDAOImpl implements UserDAO {

private SessionFactory sessionFactory;
public UserDAOImpl (SessionFactory sessionFactory){

    this.sessionFactory=sessionFactory;
}

@Override
@Transactional
public List<User> list() {

    @SuppressWarnings("unchecked")
    List<User>listUser =(List<User>)sessionFactory.getCurrentSession().createCriteria(User.class).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

    return listUser;
}   
}

User.hbm.xml code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
 <hibernate-mapping package="com.spring4hibernate4test.org.model">
 <class name="User" table="USERS" >
 <id name="id" column="USER_ID">
 <generator class="native"/>
 </id>
<property name="username" column="USERNAME" />
<property name="password" column="PASSWORD" />
<property name="email" column="EMAIL" />
 </class>

 </hibernate-mapping>

servlet-context.xml code

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<context:component-scan base-package="com.spring4hibernate4test.org" />



<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/usersdb"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</bean> 

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>

<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="userDao" class="com.spring4hibernate4test.org.dao.UserDAOImpl">
    <constructor-arg>
        <ref bean="sessionFactory" />
    </constructor-arg>
</bean> 

Root cause

 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'usersdb.USERS' doesn't exist

enter image description here

2
  • 1
    By creating the missing table in the database? What is unclear about "Table 'usersdb.USERS' doesn't exist"? Commented Dec 31, 2014 at 11:36
  • That table is there. That's what confuses me.Could it be a Connection problem @JBNizet <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/usersdb"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean> Commented Dec 31, 2014 at 11:45

1 Answer 1

5

As I remember, MySQL table/column names are by default case sensitive on linux environment, so try updating User.hbm.xml accordingly.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok that was it.I was wondering why its happening.Thanks a lot for the reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.