将 java bean 配置为 Web 服务

configuring a java bean as a web service

我遇到了这个错误:

IWAB0398E Error in generating WSDL from Java: Attempted to write duplicate schema element : {http://service.fussa.com}update

IWAB0398E Error in generating WSDL from Java: Attempted to write duplicate schema element : {http://service.fussa.com}update AxisFault faultCode: {http://xml.apache.org/axis/}Server.generalException faultSubcode: faultString: Attempted to write duplicate schema element : {http://service.fussa.com}update faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}stackTrace:Attempted to write duplicate schema element : {http://service.fussa.com}update

我的class:

public class SmartphoneService implements IDao<Smartphone> {

private static final String JPQL_SELECT_PAR_ID = "SELECT u FROM Smartphone u WHERE u.idSmartphone=:id";

// Injection du manager, qui s'occupe de la connexion avec la BDD

private EntityManagerFactory emf;
private EntityManager em;

public SmartphoneService() {
    emf = Persistence.createEntityManagerFactory("manager1");
    em = emf.createEntityManager();
}

// Enregistrement d'un nouvelle smartphone

public boolean create( Smartphone smart) {
    try {
        em.getTransaction().begin();
        em.persist(smart);
        em.getTransaction().commit();
        return true;

    } catch (Exception e) {
        if (em.getTransaction() != null) {
            em.getTransaction().rollback();
        }
    } finally {
        em.close();
        emf.close();
    }
    return false;
}

// Recherche d'une smartphone à partir de son id

public Smartphone findById(int id) {
    Smartphone smart = null;
    try {
        smart = em.find(Smartphone.class, id);
        return smart;
    } catch (Exception e) {
        if (em.getTransaction() != null) {
            em.getTransaction().rollback();
        }
    } finally {
        em.close();
        emf.close();
    }
    return smart;
}

// MAJ d'une smartphone

public boolean update(Smartphone smart) {
    try {
        em.merge(smart);
        em.getTransaction().commit();
        return true;
    } catch (Exception e) {
        if (em.getTransaction() != null) {
            em.getTransaction().rollback();
        }
    } finally {
        em.close();
        emf.close();
    }
    return false;
}

// supprimer une smartphone

public boolean delete(Smartphone smart) {
    try {
        Smartphone smartphone = findById(smart.getIdSmartphone());
        if (smartphone != null) {
            em.remove(smartphone);
            em.getTransaction().commit();
            return true;
        }
    } catch (Exception e) {
        if (em.getTransaction() != null) {
            em.getTransaction().rollback();
        }
    } finally {
        em.close();
        emf.close();
    }
    return false;
}

// findALL

public List<Smartphone> findAll() {
    List<Smartphone> smarts = null;
    try {
        Query query = em.createQuery("SELECT e FROM Smartphone e");
        smarts = (List<Smartphone>) query.getResultList();
        return smarts;
    } catch (Exception e) {
        if (em.getTransaction() != null) {
            em.getTransaction().rollback();
        }
    } finally {
        em.close();
        emf.close();
    }
    return smarts;
}

// Recherche d'un utilisateur à partir de son id

public Smartphone findById2(int id) {
    Smartphone smart = null;
    Query requete = em.createQuery(JPQL_SELECT_PAR_ID);
    requete.setParameter("id", id);
    try {
        smart = (Smartphone) requete.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
    return smart;
}

}

感谢您的帮助

这个视频帮助我解决了我的问题: Building SOAP Web Service in Java Using Eclipse