public List findByProperty(String propertyName, Object value) {
log.debug("finding FmUser instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from FmUser as model where model."
+ propertyName + "= ?";
Query queryObject = getCurrentSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
调试到“getCurrentSession().createQuery”报一个错误:
Source not found for FmUserDAO$$FastClassByCGLIB$$deecd5cd.invoke(int, Object, Object[]) line: not available
提示找不到FmUser,但我在com.fundclien.entity.FmUser是存在的,它的代码是:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* FmUser entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "FM_USER", schema = "GF", uniqueConstraints = @UniqueConstraint(columnNames = "VC_USER_CODE"))
public class FmUser implements java.io.Serializable {
@Id
@GeneratedValue
@Column(name = "L_USER_ID", unique = true, nullable = false, precision = 10, scale = 0)
public Long getLUserId() {
return this.LUserId;
}
public void setLUserId(Long LUserId) {
this.LUserId = LUserId;
}
@Column(name = "VC_USER_CODE", unique = true, nullable = false, length = 16)
public String getVcUserCode() {
return this.vcUserCode;
}
}
下面是applicationContext.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:tx="http://www.springframework.org/schema/tx">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url"
value="jdbc:oracle:thin:@127.0.0.1:1521:orcl">
</property>
<property name="username" value="gf"></property>
<property name="password" value="gf"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.fundclien.entity.FmUser</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean
id="fmUserDao" class="com.fundclien.dao.FmUserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="login" class="com.fundclient.actions.loginAction">
<property name="fmUserDao" ref="fmUserDao" />
</bean>
</beans>
求前辈帮我看看是怎么回事啊?我调用FmUser instance = (FmUser) getCurrentSession().get("com.fundclien.entity.FmUser", id);则可以取得。
------解决方案--------------------
如果你喜欢注解,把seesionFactory中的属性
<property name="annotatedClasses">
<list>
<value>com.fundclien.entity.FmUser</value>