Entity Table is not creating using JPA 2.1

后端 未结 6 911
小蘑菇
小蘑菇 2021-01-21 00:51

I am using JPA 2.1 in Netbeans to create my entity. If my database has no table then it should create table from entities.

When I deploy and run my enterprise applicati

6条回答
  •  遥遥无期
    2021-01-21 01:23

    Just in case someone is interested: It seems that since JPA 2.1 / Glassfish 4.1 you need to use your PU somewhere before the tables are created. These two lines should be enough, i.e. in an EJB:

    @PersistenceContext
    private EntityManager em;
    

    or

    @PersistenceContext(unitName = "CommonInfrastructure-ejbPU")
    private EntityManager em;
    

    See also my answer here: How to use JPA with Java EE 7, Glassfish 4.1 and Maven on JavaDB

提交回复
热议问题