初学spring,在整合hibernate后,出现下面问题:我看了教程,是不是在applicationContext.xml中要配事务? 20
org.hibernate.QueryException:couldnotresolveproperty:serviceNumof:com.acc_charge.orm....
org.hibernate.QueryException: could not resolve property: serviceNum of: com.acc_charge.orm.AccCharge201010 [from com.acc_charge.orm.AccCharge201010 as model where model.serviceNum= ?]
程序代码:
在SearchFeeAction.java中调用
List list =accCharge2010DAO.findByProperty("serviceNum", teleID);
其中teleID通过表单提交.
serviceNum是AccCharge201010.java中的一个字段。
AccChargeDAO.java下的函数是自动生成的:
public List findByProperty(String propertyName, Object value) {log.debug("finding AccCharge201010 instance with property: "+ propertyName + ", value: " + value);
try {String queryString = "from AccCharge201010 as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {log.error("find by property name failed", re);
throw re;}}
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="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url" value="jdbc:sqlserver://10.46.64.151/hffenxi"></property>
<property name="username" value="sa"></property>
<property name="password" value="hengyang"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/acc_charge/orm/AccCharge201010.hbm.xml
</value></list>
</property></bean>
<bean id="accCharge201010DAO"
class="com.acc_charge.orm.AccCharge201010DAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="/searchFee" class="com.acc_test_charge.struts.action.SearchFeeAction" singleton="false">
<property name="accCharge201010DAO">
<ref bean="accCharge201010DAO"/>
</property>
</bean>
</beans> 展开
程序代码:
在SearchFeeAction.java中调用
List list =accCharge2010DAO.findByProperty("serviceNum", teleID);
其中teleID通过表单提交.
serviceNum是AccCharge201010.java中的一个字段。
AccChargeDAO.java下的函数是自动生成的:
public List findByProperty(String propertyName, Object value) {log.debug("finding AccCharge201010 instance with property: "+ propertyName + ", value: " + value);
try {String queryString = "from AccCharge201010 as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {log.error("find by property name failed", re);
throw re;}}
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="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url" value="jdbc:sqlserver://10.46.64.151/hffenxi"></property>
<property name="username" value="sa"></property>
<property name="password" value="hengyang"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/acc_charge/orm/AccCharge201010.hbm.xml
</value></list>
</property></bean>
<bean id="accCharge201010DAO"
class="com.acc_charge.orm.AccCharge201010DAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="/searchFee" class="com.acc_test_charge.struts.action.SearchFeeAction" singleton="false">
<property name="accCharge201010DAO">
<ref bean="accCharge201010DAO"/>
</property>
</bean>
</beans> 展开
展开全部
检查在类和mapping文件中的属性名是否和你写的保持一致
另外检查此属性的getter 和setter方法是否是get/set加上“ServiceNum”
另外检查此属性的getter 和setter方法是否是get/set加上“ServiceNum”
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你还在这样设值啊?,怎么不用HIBERNATE自带的模板列?集成HIBERNATEDAOSUPPORT 里面有封装了的CRUD的方法,代码量大大减少了额!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
帮不上你,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询