XmlInverseReference, Hibernate, JAXWS and Moxy



我似乎无法让 moxy 使用 JAX-WS Web 服务并休眠。不管我做什么,@XMLInverseReference都行不通。我希望它能填充Site上的application变量。我做错了什么或理解错了什么?

我收到:org.hibernate.PropertyValueException: not-null property references a null or transient value: Site.application。如果我将@XMLElement添加到Site.application,那么我会从 JAXB 得到一个循环引用异常。

值得一提的是,所有的封送和取消编组都是由 JAX-WS WSServlet 端点处理的。

我还通过执行以下操作验证了我的jaxb.properties是否正常工作:

public class Run {
    public static void main(String[] args) throws Exception {
        System.out.println(JAXBContext.newInstance(Site.class).getClass());
    }
}


应用:
@Entity
@Table(schema = "dbo", name = "Applications")
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement
public class Application {
    @Id
    @Column(name = "id", nullable = false, insertable = false, updatable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @RemoteProperty
    @XmlElement
    private Integer id;
    @Column(name = "code", nullable = false, unique = true)
    @NaturalId
    @XmlElement
    private String code;
    @Column(name = "name")
    @XmlElement
    private String name;
    @OneToMany(mappedBy = "application", fetch = FetchType.EAGER)
    @Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
    @Cascade(value = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
    @Sort(type = SortType.NATURAL)
    @XmlElement
    private Set<Site> sites = new TreeSet<Site>();
}

网站:

@Entity
@Table(schema = "dbo", name = "Sites")
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement
public class Site implements Identifiable<Integer>, Comparable<Site> {
    @Id
    @Column(name = "id", nullable = false, insertable = false, updatable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(name = "address", unique = true)
    @NaturalId(mutable = true)
    @XmlID
    private String address;
    @Column(name = "ssl")
    @XmlAttribute(required = true)
    private boolean ssl;
    @ManyToOne
    @JoinColumn(name = "applicationCode", nullable = false, referencedColumnName = "code")
    @XmlInverseReference(mappedBy = "code")
    private Application application;
}

JAXB.properties

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

JAX-WS 实现不一定遵循 JAXB.properties。 如果您使用的是 WebLogic 12.1.1 或 GlassFish 3.1.2,则以下内容会有所帮助:

  • http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html
  • http://blog.bdoughan.com/2012/02/glassfish-312-is-full-of-moxy.html

最新更新