将java bean配置为Web服务

时间:2015-12-27 23:12:11

标签: java eclipse web-services wsdl axis

我收到此错误:

  

IWAB0398E从Java生成WSDL时出错:尝试编写重复的架构元素:{http://service.fussa.com} update

     

IWAB0398E从Java生成WSDL时出错:尝试编写重复的架构元素:{http://service.fussa.com}更新       AxisFault       faultCode:{http://xml.apache.org/axis/} Server.generalException       faultSubcode:       faultString:尝试写入重复的架构元素:{http://service.fussa.com}更新       faultActor:       faultNode:       faultDetail:       {http://xml.apache.org/axis/} stackTrace:尝试编写重复的架构元素:{http://service.fussa.com} update

我的班级:

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;
}

}

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

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