嵌套异常是javax.persistence

时间:2016-06-25 20:13:59

标签: spring hibernate bean-validation

我是JPA和Hibernate的新手。我正在尝试编码SAVE方法我收到了这个错误:

  

springframework.transaction.TransactionSystemException:无法   提交JPA事务;嵌套异常是   javax.persistence.RollbackException:提交时出错   交易

代码:

@PersistenceContext
    private EntityManager em;

    @Override
    @Transactional
    public UserMeal save(UserMeal userMeal, int userId) {
        User ref = em.getReference(User.class, userId);
        userMeal.setUser(ref);

        if (userMeal.isNew()) {
            em.persist(userMeal);
            return userMeal;
        } else {
            if (get(userMeal.getId(), userId) == null) return null;
            return em.merge(userMeal);
        }    }

0 个答案:

没有答案