无法让JPA在Wildfly 19.1上运行

问题描述

我对Wildfly还是陌生的,对JPA真的很陌生。当我尝试从DAO调用方法时,出现空异常。我建议使用@Stateless和@Inject批注进行一些更改,但DAO似乎根本没有初始化。当我尝试调用findAllClientCompanies方法时,该对象为null。

这是peristence.xml文件。

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="miscPU">
        <jta-data-source>java:/jdbc/misc</jta-data-source>
        <properties>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.transaction.flush_before_completion" value="true"/>
        </properties>
    </persistence-unit>
    <persistence-unit name="autojobsPU">
        <jta-data-source>java:/jdbc/autojobs</jta-data-source>
        <properties>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.transaction.flush_before_completion" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

这是实体声明:

@Entity
@Table(name="clientcompany")
public class ClientCompany extends Company implements Serializable {

这里是dao,findAllClientCompanies是用空异常炸毁的特定方法:

package com.lingosys.jpa;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.Query;
import java.io.Serializable;
import java.util.List;

/**
 *
 * @author mphoenix
 */
@Stateless
public class ClientCompanyDAO implements Serializable {
    @PersistenceContext(unitName="miscPU")
    private EntityManager em;

    public ClientCompanyDAO() {
    }
    
    public void create(ClientCompany clientCompany) {
        em.persist(clientCompany);
    }

    public EntityTransaction getTransaction() {
        return em.getTransaction();
    }

    public ClientCompany findClientCompany(int id) {
        ClientCompany clientCompany = (ClientCompany) em.find(ClientCompany.class,id);
        return clientCompany;
    }

    public List <ClientCompany> findAllClientCompanies() {
        TypedQuery<ClientCompany> query = em.createQuery("select c from ClientCompany c",ClientCompany.class);
        return query.getResultList();
    }

    public void delete(ClientCompany clientCompany) {
        em.remove(em.contains(clientCompany) ? clientCompany:em.merge(clientCompany));
    }

    public int deleteAllClientCompanies() {
        Query query = em.createQuery("delete from ClientCompany");
        return query.executeUpdate();
    }

}

这是调用dao方法的JSF bean:

    @Inject
    private ClientCompanyDAO daoClientCompany;
    private boolean noValidEmail = false;
    private String fakeEmailUserName = "";
    private Connection conn;
    private List<ClientCompany> unsortedList;
    private String specialInstructions;
    private String createdBy;

    //XML processing variables
    private Document document = null;
    private String xmlMsgs = "";
    private boolean xmlLoaderDisabled = false;

    //prospect handling variables
    private boolean prospectDisabled = false;
    private static final String YES = "Yes";

    //Legal entity based variables
    boolean entitySet = false;
    boolean lls = false;
    boolean clientIDSet = false;
    boolean billingInstructionsSet = false;
    boolean billingEmailSet = false;
    private static final String[] IS_LLS = {"LLS","Coto/TI","LLS-UK"};

    boolean companyLoggedOn = false;
    private boolean processDisabled = true;
    private boolean userSpecificEntity = false;

    /**
     * Constructor initializes Web Service client,Hibernate DAOs,UI lists,and
     * client view.
     *
     */
    public ClientCreatorBean() {
        fmrws = new FormerWSOps();

        try {
            unsortedList = daoClientCompany.findAllClientCompanies();
            view = fmrws.getClientCompanyView();
        } catch (Exception ex) {
            java.util.logging.Logger.getLogger(ClientCreatorBean.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
        }
        reset();
  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)