-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Configure hibernate problem
PostPosted: Mon Sep 25, 2006 1:30 am 
Beginner
Beginner

Joined: Mon Sep 18, 2006 5:33 am
Posts: 25
hi,

Im new to hibernate, and im trying to add hibernate persistance to my spring app. My spring app is just a simple form with 5 or so fields which i want to store in a table. Im getting the following error and my code is below that. Also if you see any other errors, especially in that way i have configured my app, please mention. Thanks

Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'photoinfoForm' defined in ServletContext resource [/WEB-INF/photomapper-servlet.xml]: Cannot resolve reference to bean 'photoMan' while setting bean property 'photoManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'photoMan' defined in ServletContext resource [/WEB-INF/photomapper-servlet.xml]: Cannot resolve reference to bean 'photoManDao' while setting bean property 'photoManagerDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'photoManDao' defined in ServletContext resource [/WEB-INF/photomapper-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/hibernate/Session


the form bean Photo
Code:
package src.bus;

import java.io.Serializable;
import java.util.Date;

public class Photo implements Serializable {
   
   private String location; //where photo was taken
   private String photographer; //map to username
   private String datetaken;
   private String description;
   
   public String getDatetaken() {
      return datetaken;
   }
   
   public void setDatetaken(String datetaken) {
      this.datetaken = datetaken;
   }
   
   public String getDescription() {
      return description;
   }
   
   public void setDescription(String description) {
      this.description = description;
   }      
   
   public String getLocation() {
      return location;
   }
   
   public void setLocation(String location) {
      this.location = location;
   }
   
   public String getPhotographer() {
      return photographer;
   }
   
   public void setPhotographer(String photographer) {
      this.photographer = photographer;
   }
}


my controller
Code:
package src.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

import src.bus.Photo;
import src.bus.PhotoManager;

public class PhotoinfoController extends SimpleFormController{
   
   private PhotoManager pm = new PhotoManager();

   protected ModelAndView onSubmit(HttpServletRequest request,
         HttpServletResponse response, Object command, BindException errors) {
      
      Photo bean = (Photo)command;
      pm.setPhoto(bean);
      // write collected form data to the database table
      
      //return super.onSubmit(request, response, command, errors);
      return new ModelAndView(new RedirectView(getSuccessView()));

   }
}



my hibernate doa and doa interface
Code:
import java.util.List;

import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import org.hibernate.Query;
import org.hibernate.Session;
import src.bus.Photo;

public class PhotoinfoDaoHib extends HibernateDaoSupport implements PhotoinfoDao  {

   public Photo getPhotoinfo(int id) {
      
      Session session = HibernateUtil.currentSession();
      session.beginTransaction();
      Query query = session.createQuery("from Photoinfo pi where pi.photoinfoId = :id");
      query.setInteger("id", id);
         
      HibernateUtil.closeSession();
      
      return (Photo) query.uniqueResult();      
   }

   public List getPhotoinfoList() {
      // TODO Auto-generated method stub
      return null;
   }

   public void addPhotoinfo(Photo p) {
      getHibernateTemplate().saveOrUpdate(p);
      
   }   
}



--

package src.db;

import java.util.List;

import src.bus.Photo;

public interface PhotoinfoDao {
   
   public Photo getPhotoinfo(int id);
   public List getPhotoinfoList();
   public void addPhotoinfo(Photo p);

}




hibernate.cfg.xml
Code:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
  </bean>

  <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="mappingResources">
      <list>
        <value>photoinfo.hbm.xml</value>
      </list>
    </property>
    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.MySQLDialect
      </value>
    </property>
  </bean>



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

<!--
   - Application context definition for "photomapper" DispatcherServlet.
-->

<beans>
      
   <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">       
         <props>                     
            <prop key="/photoinfo.htm">photoinfoForm</prop>            
         </props>
      </property>
    </bean>
   
   <bean id="photoinfoValidator"
      class="src.validator.PhotoinfoValidator" />
   <bean id="photoinfoForm"
      class="src.controller.PhotoinfoController">
      <property name="sessionForm">
         <value>true</value>
      </property>
      <property name="commandName">
         <value>photo</value>
      </property>
      <property name="commandClass">
         <value>src.bus.Photo</value>
      </property>
      <property name="validator">
         <ref bean="photoinfoValidator" />
      </property>
      <property name="formView">
         <value>photoinfo</value>
      </property>
      <property name="successView">
         <value>successful</value>
      </property>
      <property name="photoManager">
            <ref bean="photoMan"/>
        </property>
   </bean>
   
   <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
       <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
       <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
       <property name="username" value="sa"/>
       <property name="password" value=""/>
   </bean>
   
   <bean id="photoManDao" class="src.db.PhotoinfoDaoHib">
        <property name="dataSource">
            <ref bean="myDataSource"/>
        </property>
    </bean>

    <bean id="photoMan" class="src.bus.PhotoManager">
        <property name="photoManagerDao">
             <ref bean="photoManDao"/>
        </property>
    </bean>
          
   <bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass">
         <value>org.springframework.web.servlet.view.JstlView</value>
      </property>
      <property name="prefix">
         <value>/WEB-INF/jsp/</value>
      </property>
      <property name="suffix">
         <value>.jsp</value>
      </property>
   </bean>
   
</beans>



web.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>

<web-app>
   <servlet>
      <servlet-name>photomapper</servlet-name>
      <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
      </servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
      <servlet-name>photomapper</servlet-name>
      <url-pattern>*.htm</url-pattern>
   </servlet-mapping>

   <welcome-file-list>
      <welcome-file>index.htm</welcome-file>
   </welcome-file-list>
   
   <taglib>
      <taglib-uri>/spring</taglib-uri>
      <taglib-location>/WEB-INF/spring.tld</taglib-location>
   </taglib>
</web-app>


photoinfo.hbm.xml
Code:
<hibernate-mapping>
   <class name="Photo" table="Photoinfo">
      <id name="photoinfoId" column="photoinfoId"
         type="java.lang.Integer" unsaved-value="-1">
         <generator class="native"></generator>
      </id>
      <property name="location" column="location" type="string" />
      <property name="photographer" column="photographer"
         type="string" />
      <property name="datetaken" column="datetaken" type="string" />
      <property name="description" column="description" type="string" />
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 1:34 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Code:
extends HibernateDaoSupport


Remove that.

Code:
      Session session = HibernateUtil.currentSession();


Remove that.

http://hibernate.org/42.html (and all links from this page)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 2:08 am 
Beginner
Beginner

Joined: Mon Sep 18, 2006 5:33 am
Posts: 25
k, ive changed that. Anything else, especially anything to do with my configuration.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.