I am working on my first hibernate project. I have been trying to get this to work for so long that my head is throbbing. Can someone spot the error that is giving me the "No CurrentSessionContext configured!" error? I am sure I have missed something simple.
Code:@Repository public class ContentComponentDAOImpl implements ContentComponentDAO { @Autowired private SessionFactory sessionFactory; public ContentComponentDAOImpl(SessionFactory sessionFactory) { setSessionFactory(sessionFactory); } @Override public List<ContentComponent> getContentComponents() throws DAOException { Session session = sessionFactory.getCurrentSession(); List<ContentComponent> documents = null; try { documents = (List<ContentComponent>) session.createQuery("from cmsutil.cmsutil.wp_content_components").list(); } catch (HibernateException e) { e.printStackTrace(); } return documents; }
Code:public class Driver { public static void main(String[] args) throws DAOException { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); ContentComponentDAOImpl c = new ContentComponentDAOImpl(sessionFactory); List l = c.getContentComponents(); }
applicationcontext.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://mydrupal:3306/cmsutil</property> <property name="hibernate.connection.username">cms</property> <property name="hibernate.connection.password">xxxx</property> </session-factory> </hibernate-configuration>
Code:<bean id="dataSource"> class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" </bean> </beans>


Reply With Quote