How to create Jpa repository dynamically inside a class?

后端 未结 1 1513
星月不相逢
星月不相逢 2020-12-19 00:08

How do I create and instantiate a jpa repository inside a class? I\'m in a situation where I have to create repositories for different entities inside a generic class.

相关标签:
1条回答
  • 2020-12-19 00:22

    I finally got it working this way,

    SimpleJpaRepository<User, Serializable> jpaRepository;
    jpaRepository = new SimpleJpaRepository<User, Serializable>(
        User.class, entityManager);
    

    With SimpleJpaRepository, I can use all repository methods.

    jpaRepository.save(user);
    
    0 讨论(0)
提交回复
热议问题