Tag: spring orm

org.hibernate.MappingException:未知实体:在spring orm中

我得到以下exception org.hibernate.MappingException:未知实体:com.sample.Student 我在Stackoverflow上看到了很多相同问题的答案,但是他们都建议使用来自javax.persistence而不是hibernate的@Entity注释,在我的例子中我只使用它来自javax.persistence但仍然得到这个exception。 我的POJO课程 package com.sample; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table public class Student { @Id int id; public int getId() { return id; } public void setId(int id) { this.id = id; } String firstName; String lastName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = […]

为什么openSession不起作用,但getCurrentSession在Spring Hibernate中工作

我已经编写了一个示例Spring Hibernate应用程序o了解Spring hibernate集成的工作原理。 这是我的applicationContext.xml org.hibernate.dialect.Oracle10gDialect true 然后,我的服务类就是这样 package com.general; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; @Service(“employeeService”) public class EmployeeServiceImpl implements EmployeeService{ @Autowired private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Transactional public void saveEmployee(Employee emp) { Session session = sessionFactory.getCurrentSession();//.openSession(); session.save(emp); } } 而我的主要课程是 public […]