How to define two persistence units (one for production, one for unit testing)?

后端 未结 4 1001
一整个雨季
一整个雨季 2020-12-31 14:25

This is my stateless bean:

@Stateless
public class Finder {
  @PersistenceContext(unitName = \"production\")
  EntityManager em;
  [...]
}

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 14:54

    You can create a second persistence unit in your configuration, but that doesn't necessarily mean you should. Multiple PUs are of course entirely right and proper, but I'd steer clear of mixing them up when they're specifically for different environments, e.g. production versus test.

    In your instance, I'd have two persistence configuration files, and have Ant / Maven / build tool of choice copy / rename the correct one when appropriate.

提交回复
热议问题