@PersistenceUnit annotation won't create an EntityManageFactory emf=null

喜夏-厌秋 提交于 2019-11-28 00:07:31

If the annotated object is not managed by a container (either spring/CDI/EJB container), nothing gets injected into it.

So depending on your environment, obtain a contextual instance of that object.

If you are not using any of the above technologies (spring/CDI/EJB) - then you can't use @PersistenceUnit and @PersistenceContext. Use the manual way to obtain the unit.

For some reasons this happens when using this in you persistence.xml

<provider>org.hibernate.ejb.HibernatePersistence</provider>

switching to

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

fixes the problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!