日期:2014-05-18 浏览次数:20618 次
getHibernateTemplate().find("select user from User user where user.name = '123'" );的时候一直报错,could not resolve property: name of: com.myblog.entity.User [select user from com.myblog.entity.User user where user.name = '123'],我检查了配置感觉没有错啊,
public class User {
private int Id;
private String Name;
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
<class name="com.myblog.entity.User">
<id name="Id">
<generator class="assigned"></generator>
</id>
<property name="Name"></property>
<property name="Password"></property>
<property name="Nickname"></property>
<property name="Question"></property>
<property name="Answer"></property>
<property name="Header"></property>
<property name="Visitscounts"></property>
<property name="Visitscountstoday"></property>
</class>
<!-- 定义数据源 -->求大神帮忙看下
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/myblog</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>admin</value>
</property>
</bean>
<!-- 定义SessionFactory -->
<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.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/myblog/entity/User.hbm.xml</value>
</list>
</property>
</bean>
<!-- 定义HibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>