直接从 Spring Service bean 而不是 @Repository bean 使用实体管理器有什么缺点吗
@Service
public class SomeService {
@PersistenceContext EntityManager em;
@Transactional(....)
public void doSomething(....)
{
// use entity manager here
}
}
对比
@Repository
public class SomeRepository {
@PersistenceContext EntityManager em;
public void doSomething(....)
{
// use entity manager here
}
}