Spring JPA存储库(无法在托管事务中设置自动提交)

时间:2019-03-19 22:54:41

标签: spring hibernate spring-mvc spring-data-jpa

我正在开发的应用程序具有从CrudRepository扩展的3个存储库,当我尝试将其托管在WildFly上时,我收到了此错误

java.sql.SQLException:IJ031017:您无法在托管事务期间设置自动提交

然后,在搜索互联网后,我找到了解决方法here

通过将@Eager添加到我的一个存储库中(我认为是引起问题的原因),但是后来我决定再添加2个从CrudRepository扩展的存储库,突然错误再次出现,我尝试混合使用@Eager批注并将其放在我所有的存储库声明中,但没有更改

这些是存储库

@Repository
public interface ReceivedLetterDao extends CrudRepository<ReceivedLetter, Long> {}


@Repository
public interface SentLetterDao extends CrudRepository<SentLetter, Long> {}

@Repository
public interface RoleDao extends CrudRepository<Role, Long> {
    List<Role> findByUsernameAndDepartment(String username, Integer department);
}

@Repository
public interface DepartmentDao extends CrudRepository<Department, Integer> {
    Iterable<Department> findAll();
}

@Repository("userRepository")
public interface UserDao extends CrudRepository<ActiveUser, Long> {
    @Query("SELECT user FROM ActiveUser user WHERE user.username = :username AND user.department.id = :department")
    ActiveUser findUser(@Param("username") String username,@Param("department") Integer department);

    ActiveUser findById(long id);
}

预先感谢

0 个答案:

没有答案