|
|
mons.dbcp.BasicDataSourcequot; destroy-method=quot;closequot;gt; lt;property name=quot;driverClassNamequot; value=quot;org.hsqldb.jdbcDriverquot;/gt; lt;property name=quot;uclquot; value=quot;jdbc:hsqldb:hsql--localhost:9001quot;/gt; lt;property name=quot;usernamequot; value=quot;saquot;/gt; lt;property name=quot;passwordquot; value=quot;quot;/gt; lt;/beangt;
lt;bean id=quot;mySessionFactoryquot; class=quot;org..orm.hibernate3.LocalSessionFactoryBeanquot;gt; lt;property name=quot;dataSourcequot; ref=quot;myDataSourcequot;/gt; lt;property name=quot;mappingResourcesquot;gt; lt;listgt; lt;valuegt;photoinfo.hbm.xmllt;/valuegt; lt;/listgt; lt;/propertygt; lt;property name=quot;hibernatePropertiesquot;gt; lt;valuegt; hibernate.dialect=org.hibernate.dialect.MySQLDialect lt;/valuegt; lt;/propertygt; lt;/beangt;
my dispatcher servlet: photomapper-servlet
Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;
lt;!--
- Application context definition for quot;photomapperquot; DispatcherServlet.
--gt;
lt;beansgt;
lt;bean id=quot;uclMappingquot; class=quot;org..web.servlet.handler.SimpleuclHandlerMappingquot;gt;
lt;property name=quot;mappingsquot;gt;
lt;propsgt;
lt;prop key=quot;/photoinfo.htmquot;gt;photoinfoFormlt;/propgt;
lt;/propsgt;
lt;/propertygt; lt;/beangt;
lt;bean id=quot;photoinfoValidatorquot;
class=quot;src.validator.PhotoinfoValidatorquot; /gt;
lt;bean id=quot;photoinfoFormquot;
class=quot;src.controller.PhotoinfoControllerquot;gt;
lt;property name=quot;sessionFormquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;property name=quot;commandNamequot;gt;
lt;valuegt;photolt;/valuegt;
lt;/propertygt;
lt;property name=quot;commandClassquot;gt;
lt;valuegt;src.bus.Photolt;/valuegt;
lt;/propertygt;
lt;property name=quot;validatorquot;gt;
lt;ref bean=quot;photoinfoValidatorquot; /gt;
lt;/propertygt;
lt;property name=quot;formViewquot;gt;
lt;valuegt;photoinfolt;/valuegt;
lt;/propertygt;
lt;property name=quot;successViewquot;gt;
lt;valuegt;successfullt;/valuegt;
lt;/propertygt;
lt;property name=quot;photoManagerquot;gt;lt;ref bean=quot;photoManquot;/gt; lt;/propertygt;
lt;/beangt;
lt;bean id=quot;myDataSourcequot; class=quot;org..jdbc.datasource.DriverManagerDataSourcequot; destroy-method=quot;closequot;gt; lt;property name=quot;driverClassNamequot; value=quot;org.hsqldb.jdbcDriverquot;/gt; lt;property name=quot;uclquot; value=quot;jdbc:hsqldb:hsql--localhost:9001quot;/gt; lt;property name=quot;usernamequot; value=quot;saquot;/gt; lt;property name=quot;passwordquot; value=quot;quot;/gt;
lt;/beangt;
lt;bean id=quot;photoManDaoquot; class=quot;src.db.PhotoinfoDaoHibquot;gt; lt;property name=quot;dataSourcequot;gt;lt;ref bean=quot;myDataSourcequot;/gt; lt;/propertygt; lt;/beangt;
lt;bean id=quot;photoManquot; class=quot;src.bus.PhotoManagerquot;gt; lt;property name=quot;photoManagerDaoquot;gt; lt;ref bean=quot;photoManDaoquot;/gt; lt;/propertygt; lt;/beangt;
lt;bean id=quot;viewResolverquot;
class=quot;org..web.servlet.view.InternalResourceViewResolverquot;gt;
lt;property name=quot;viewClassquot;gt;
lt;valuegt;org..web.servlet.view.JstlViewlt;/valuegt;
lt;/propertygt;
lt;property name=quot;prefixquot;gt;
lt;valuegt;/WEB-INF/jsp/lt;/valuegt;
lt;/propertygt;
lt;property name=quot;suffixquot;gt;
lt;valuegt;.jsplt;/valuegt;
lt;/propertygt;
lt;/beangt;
lt;/beansgt;
web.xml
Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'dtd/web-app_2_3.dtd'gt;
lt;web-appgt;
lt;servletgt;
lt;servlet-namegt;photomapperlt;/servlet-namegt;
lt;servlet-classgt;
org..web.servlet.DispatcherServlet
lt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;
lt;servlet-mappinggt;
lt;servlet-namegt;photomapperlt;/servlet-namegt;
lt;ucl-patterngt;*.htmlt;/ucl-patterngt;
lt;/servlet-mappinggt;
lt;welcome-file-listgt;
lt;welcome-filegt;index.htmlt;/welcome-filegt;
lt;/welcome-file-listgt;
lt;taglibgt;
lt;taglib-urigt;/springlt;/taglib-urigt;
lt;taglib-locationgt;/WEB-INF/spring.tldlt;/taglib-locationgt;
lt;/taglibgt;
lt;/web-appgt;
photoinfo.hbm.xml
Code:
lt;hibernate-mappinggt;
lt;class name=quot hotoquot; table=quot hotoinfoquot;gt;
lt;id name=quot;photoinfoIdquot; column=quot;photoinfoIdquot;
type=quot;java.lang.Integerquot; unsaved-value=quot;-1quot;gt;
lt;generator class=quot;nativequot;gt;lt;/generatorgt;
lt;/idgt;
lt;property name=quot;locationquot; column=quot;locationquot; type=quot;stringquot; /gt;
lt;property name=quot;photographerquot; column=quot;photographerquot;
type=quot;stringquot; /gt;
lt;property name=quot;datetakenquot; column=quot;datetakenquot; type=quot;stringquot; /gt;
lt;property name=quot;descriptionquot; column=quot;descriptionquot; type=quot;stringquot; /gt;
lt;/classgt;
lt;/hibernate-mappinggt;Seems to be the same problem you already described here. Did you see my answer there?
Regards,
Andreas
Yeah, just looks like it can't find the class (either the Jar isn't there when you run or your code is importing the wrong class/package)... Should be easy to fix...
The latter one is it. In the other thread is stated that hibernate 3.x is used. Here, however, the HibernateDaoSupport class for 2.x is being used.
I fixed that error a while ago, i dont think its the same problem because im not longer referencing the old imports/packages. But i could be wrong, can you see any references to the old packages?
Or if anyone has any other ideas that would be appreciated
Code:
import java.util.List;
import org..orm.hibernate.support.HibernateDaoSupport;
import org.hibernate.Query;
import org.hibernate.Session;
import src.bus.Photo;
public class PhotoinfoDaoHib extends HibernateDaoSupport implements PhotoinfoDao {
...
The first import statement refers to the 2.x support package. It has to be org..orm.hibernate3.support.Hiberna teDaoSupport.
Regards,
Andreas
thanks, that bit of the error is gone. The new error is the followingCode:
org..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..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..beans.factory.BeanCreationException: Error creating bean with name 'photoManDao' defined in ServletContext resource [/WEB-INF/photomapper-servlet.xml]: Error setting property values; nested exception is org..beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [src.db.PhotoinfoDaoHib]: Bean property 'dataSource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
Anyone have ideas on how to fix them? they seem to be configuration errors, im not sure how to fix them.
thanks
btw, here is the changes i made to correct the importCode:
package src.db;
import java.util.List;
import org..orm.hibernate3.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.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery(quot;from Photoinfo pi where pi.photoinfoId = :idquot;);
query.setInteger(quot;idquot;, id);
session.close();
return (Photo) query.uniqueResult();
}
public List getPhotoinfoList() {
// TODO Auto-generated method stub
return null;
}
public void addPhotoinfo(Photo p) {
getHibernateTemplate().saveOrUpdate(p);
}
}The error message is pretty straightforward. In the bean named quot;photoManDaoquot; you have an (inherited) property named quot;dataSourcequot;. On wiring this property you refer to a bean named quot;dataSourcequot;. This bean does not exist. In fact, in your config I see you have a bean quot;myDataSourcequot;. Actually the reference seems to be ok there, I suspect something has changed meanwhile.
Btw I find it confusing that you have your datasource defined in two different context files. It is not recommended to have Daos and data sources in the servlet context, but in the parent application context.
Regards,
Andreas
hmm are you refering to this bean, i am refering to myDataSource arent I?Code:
lt;bean id=quot;photoManDaoquot; class=quot;src.db.PhotoinfoDaoHibquot;gt; lt;property name=quot;dataSourcequot;gt;lt;ref bean=quot;myDataSourcequot;/gt; lt;/propertygt;Yes I am referring to that bean. But sorry, it seems I confused things with JdbcDaoSupport
The solution is this: The bean does not have a quot;dataSourcequot; property but a quot;sessionFactoryquot; property. So you have to pass in the session factory to that property and not your data source.
Hope that helps,
Andreas |
|