This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Problem in connecting HIbernate, exception is no property found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Problem in connecting HIbernate, exception is no property found" Watch "Problem in connecting HIbernate, exception is no property found" New topic
Author

Problem in connecting HIbernate, exception is no property found

sachin yadav
Ranch Hand

Joined: Nov 24, 2005
Posts: 156
I am using hibernate to connect to mySql database. My code for this in servlet.xml is:

springFirst-servlet.xml


<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/emp" />
<property name="username" value="XXX" />
<property name="password" value="XXXXX" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="useTransactionAwareDataSource" value="true" />
<property name="mappingResources">
<list>
<value>TestForm.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="connection.pool_size">1</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.HSQLDialect
</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">
false
</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>


TestForm.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.sachin.first">
<class name="TestForm" table="employee1">
<id name="_name" column="eid" unsaved-value="null">
<generator class="assigned"></generator>
</id>
<property name="_comments" type="string">
<column name="ename"></column>
</property>
</class>
</hibernate-mapping>


TestForm.java


package com.sachin.first;

public class TestForm
{
private String _name = "";
private String _comments = "";


public String getName()
{
return _name;
}

public void setName(String name)
{
_name = name;
}

public String getComments()
{
return _comments;
}

public void setComments(String comments)
{
_comments = comments;
}


}


and the error is:


Exception

javax.servlet.ServletException: Servlet.init() for servlet spring threw exception
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:825)
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:738)
org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:526)
org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:595)

root cause

org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Initialization of bean failed; nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for _name in class com.sachin.first.TestForm
org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:403)
org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:277)
org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:313)
org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:139)
org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:3 06)
org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:251 )
org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:220)
org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:112)
javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:825)
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:738)
org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:526)
org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:595)





I am using tomcat. I search a lot but couldn't found the problem area. My validators are working fine along with the rest of the code but exceptions start occuring as soon as i introduce hibernate. Please suggest me what should i do
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9924
    
158





The Hibernate POJOs follow JavaBean naming conventions. So change your hbm to:




[My Blog] [JavaRanch Journal]
sachin yadav
Ranch Hand

Joined: Nov 24, 2005
Posts: 156
Thanks buddy, now it's working. Thanks for the help.
 
Consider Paul's rocket mass heater.
 
subject: Problem in connecting HIbernate, exception is no property found
 
Similar Threads
org hibernate InvalidMappingException : Could not parse mapping document from invalid
Error creating bean with name 'sessionFactory'
problem with hibernate integration
Hibernate, Spring and H2
unsatisfied Dependancy exception