re: Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解(二)[未登录]
2012-03-11 14:31 |
我自己搭了一个框架:用Sping3.1.0 和hibernate 1.5.6 Model注解我写好了
package com.test.service;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.warrior.model.SySUser;
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private SessionFactory sessionFactory;
public boolean checkLogin(String userName, String password) {
if("warrior".equals(userName) && "123456".equals(password))
return true;
else
return false;
}
public void save(SySUser user) {
Session s = sessionFactory.openSession();
try{
Transaction t = s.beginTransaction();
t.begin();
s.save(user);
t.commit();
} catch(Exception e){
e.printStackTrace();
}finally{
s.close();
}
}
}
SessionFactory 的配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.test.model.SySUser</value>
</list>
</property>
</bean>
服务器启动没有错,但保存对象的时候就报错
org.hibernate.MappingException: Unknown entity
Email : sky402100@126.com
求指导
回复 更多评论