Multiple database with Spring+Hibernate+JPA

后端 未结 6 1525
别跟我提以往
别跟我提以往 2020-12-04 13:43

I\'m trying to configure Spring+Hibernate+JPA for work with two databases (MySQL and MSSQL).

My datasource-context.xml:



        
6条回答
  •  离开以前
    2020-12-04 14:01

    Justin, number 3 can be done in a more standard way like this:

    1. In your Spring context:

      
      
    2. In your Spring-managed DAOs (note the unitName property):

      @PersistenceContext(unitName = "pu1"`) protected EntityManager entityManager;
      

    This way a properly intantiated EntityManager corresponding to the persistence unit named "pu1" would be injected in the corresponding DAOs.

提交回复
热议问题