Entity Table is not creating using JPA 2.1

后端 未结 6 907
小蘑菇
小蘑菇 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:39

    Anyway, I managed to resolve this problem.

    You need to do something using JPA before the table can be created.

    For example...

    package sessionBean;
    
    import javax.ejb.Stateless;
    import entity.userEntity;
    import javax.persistence.EntityManager;
    import javax.persistence.NoResultException;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    
        @Stateless
        public class userSessionBean implements userSessionBeanLocal {
    
            @PersistenceContext
            private EntityManager entityManager;
    
            @Override
            public userEntity getUser(String userName) {
                Query query = entityManager.createQuery("SELECT u FROM userEntity u WHERE u.userName = :inUserName");
                query.setParameter("inUserName", userName);
                userEntity systemUser = null;
                try {
                    systemUser = (userEntity) query.getSingleResult();
                } catch (NoResultException ex) {
                    ex.printStackTrace();
                }
                return systemUser;
            }
    
    
        }
    

提交回复
热议问题