我似乎无法让 moxy 使用 JAX-WS Web 服务和休眠。尽管我做了什么,@XMLInverseReference
但不起作用。我希望它能够application
在 a 上填充变量Site
。我在做什么或理解错误?
我收到: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