• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About using HibernateDaoSupport.java, please help me

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to make user identified function using spring & hibernate& struts.But when start the web application,there are some errors, see the following:

-------------------------------------------------------------------
java.lang.IllegalArgumentException: No SessionFactory specified:

org.snailheart.dao.BaseDAO.openSession(BaseDAO.java:15)



-------------------------------------------------------------------
Who can help me, I�ll thank you very much!

To introduce my web program:

1. Create a BaseDAO.java, it extends HibernateDaoSupport,the following is the program.

package test.dao;

import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import org.springframework.orm.hibernate.SessionFactoryUtils;
import net.sf.hibernate.Session;
import net.sf.hibernate.Query;
import net.sf.hibernate.HibernateException;

public class BaseDAO extends HibernateDaoSupport {
public Session openSession() {
return SessionFactoryUtils.getSession(getSessionFactory(), false);
}

public Query getQuery(String query) throws HibernateException{
Session session = this.openSession();
return session.createQuery(query);
}
}



2. Create UserDAOHBImpl.java, it extends BaseDAO.java. In it, I want to perform accessing a Oracle DB.The following is the program.

package test.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import net.sf.hibernate.Session;
import net.sf.hibernate.Query;
import net.sf.hibernate.HibernateException;

import test.dao.BaseDAO;
import test.dao.UserDAO;
import test.domain.User;
import test.dto.UserDTO;

public class UserDAOHBImpl extends BaseDAO implements UserDAO {

public User getUser(UserDTO userDTO) {
String userName = userDTO.getUserName();
String pwd = userDTO.getPassword();

String queryStr = "select user from User where User.userName =:name and
User.passwd = wd";

Query query = this.getQuery(queryStr);
query.setString("name", userName);
query.setString("pwd", pwd);

List userList = query.list();
if(userList != null) {
user = (User)userList.get(0);
}else {
user = null;
}
}
}



3. The following is the configuration file: applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="oracleDS"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>

<property name="url">
<value>jdbc racle:thin:@localhost:1521 radb</value>
</property>

<property name="username">
<value>test</value>
</property>

<property name="password">
<value>test</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean">

<property name="dataSource">
<ref local="oracleDS"/>
</property>

<property name="mappingDirectoryLocations">
<list>
<value>classpath:/org/snailheart/domain/hbm</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>


<bean id="userDAO" class="org.snailheart.dao.hibernate30.UserDAOHBImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

</beans>



4. In a Action class of Struts, invoking the method: getUser(UserDTO userDTO),at this moment there occur some errors. See the following,please:

java.lang.IllegalArgumentException: No SessionFactory specified:

org.snailheart.dao.BaseDAO.openSession




 
charles qi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couldn't nobody help me?
wu...

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charles?

Any luck!
If you got any solution then please share it with community.

Cheers
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic