How to create Jpa repository dynamically inside a class?

后端 未结 1 1523
星月不相逢
星月不相逢 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 jpaRepository;
    jpaRepository = new SimpleJpaRepository(
        User.class, entityManager);
    

    With SimpleJpaRepository, I can use all repository methods.

    jpaRepository.save(user);
    

    0 讨论(0)
提交回复
热议问题