Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT inste

您不能像这样启动事务。

您应该像这样使用声明性事务:

@Service
@Persistent
public class ProjectService {
    @PersistenceContext
    private EntityManager em;
    private Session session;

    @Transactional
    public void insertEmployee throws Exception
    {
         em.createNativeQuery("insert into Employee (name,surname,) values('Phil','Bob'").executeUpdate();      
    }
}

请在 Spring 文档中阅读有关事务的更多信息:Data Access


版权声明:本文为allway2原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。