我似乎无法使用JAX-WS Web服务和hibernate。尽管我做了什么,@XMLInverseReference
不起作用。我希望它能填写application
上的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
答案 0 :(得分:0)
JAX-WS实现不一定尊重JAXB.properties。如果您使用的是WebLogic 12.1.1或GlassFish 3.1.2,则以下内容将有所帮助: