【问题标题】:SOAP with Entity class带有实体类的 SOAP
【发布时间】:2015-02-12 17:26:49
【问题描述】:

我有这个实体类:

package com.model;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity
import com.model.BaseEntity;
import com.model.CustomerPK;

@Entity
@Table(name = "CUSTOMER")
public class Customer extends BaseEntity {
    
    private static final long serialVersionUID = -625869124375935833L;
    
    @EmbeddedId
    private CustomerPK id;
    
    @Column(name = "NAME", length = 70, nullable = true)
    private String name;
    
    @Column(name = "PHONE", length = 20, nullable = true)
    private String phone;
    
    @Column(name = "ADDRESS", length = 40, nullable = true)
    private String address;
    
    @Column(name = "CITY", length = 30, nullable = true)
    private String city;
    
    ....
    
}

我有这个 Web 服务类:

package com.ws;

import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;
import com.servico.WSService;

import com.model.Customer;


@WebService(serviceName = "customerWS")
public class CustomerWS {

    @Inject
    private WSService wss;

    @WebMethod(operationName = "validateCustomer")
    public List<String> validateCustomer(
            @XmlElement(name = "customer", required = true) Customer customer) {
        return wss.validateCustomer(customer);
    }
}

当我尝试启动服务时,会显示此错误:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://--.--.-----.-----.-----.----.----.--/}baseEntity". Use @XmlType.name and @XmlType.namespace to assign different names to them.
    this problem is related to the following location:
        at ------.BaseEntity
        at ------.model.BaseEntity

    this problem is related to the following location:
        at ------.model.BaseEntity
    

我无法编辑 BaseEntity 类。有没有办法在不注释 BaseEntity 类的情况下创建 Web 服务?

编辑:

我不想使用 MOXy 框架,因为我已经有在线的 Web 服务。我的问题是如果我只能编组 Customer 类,而没有她的 BaseEntity 类。 附加信息:我的客户和我的 Web 服务可以访问 Customer 类所在的同一个包。

【问题讨论】:

标签: java web-services ejb entity jax-ws


【解决方案1】:

如果可以使用MOXy,那就有option

如果你不能注释类

MOXy 提供了一个外部映射文档扩展,可用于将 JAXB 元数据应用于无法更改的类。

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="**com.common**">
    <java-types>
        <java-type name="City">
            <xml-type name="city2"/>
        </java-type>
    </java-types>
</xml-bindings>

【讨论】:

  • 我的项目中没有使用 MOXy。是否可以选择仅编组 Customer 类而不编组 BaseEntity 类?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-06
相关资源
最近更新 更多