나는 이미 가지고있는 클래스를 보여주고 있으며 jaxb와 직렬화하려고합니다. 이제 관계를 이해할 수 있듯이일대 다 및 다 대 일 MOXy @XmlInverseReference EclipseLink 2.5
public class Person {
@Id
@Column(name = "ID")
private Integer id;
@Column(name = "FIRST_NAME")
@NotNullOnlyJsp
private String firstName;
@Column(name = "LAST_NAME")
@NotNullOnlyJsp
private String lastName;
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "person")
@org.hibernate.annotations.OrderBy(clause = "start_date asc")
private Set<Position> positionSet = new LinkedHashSet<Position>();
// getter and setter and other methods..
}
public class Position{
@Id
@Column(name = "ID")
private Integer id;
@Column(name = "FK_PERSON")
@NotNull
private Integer personId;
@Column(name = "FK_POSITION_TYPE")
@NotNull
private Integer positionTypeId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_POSITION_TYPE", insertable = false, updatable = false)
private Entity positionType;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_PERSON", insertable = false, updatable = false)
// I need this annotation to avoid ciclyc graph
@XmlInverseReference(mappedBy="positionSet")
private Person person;
@Column(name = "FK_ORG_UNIT")
@NotNull
private Integer organizationUnitId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_ORG_UNIT", insertable = false, updatable = false)
// I need this annotation to avoid ciclyc graph
@XmlInverseReference(mappedBy="organizationUnitPositionSet")
private OrganizationUnit organizationUnit;
// getter and setter and other methods..
}
public class OrganizationUnit{
@Id
@Column(name = "ID")
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FK_ORG_UNIT_TYPE", insertable = false, updatable = false)
private OrganizationUnitType organizationUnitType;
@Column(name = "FK_ORG_UNIT_TYPE")
private Integer organizationUnitTypeId;
@Column(name = "DESCRIPTION", length = 4000)
@NotNull
private String description;
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "organizationUnit")
@org.hibernate.annotations.OrderBy(clause = "start_date asc")
// I need this annotation to avoid ciclyc graph
private Set<Position> organizationUnitPositionSet = new LinkedHashSet<Position>();
// getter and setter and other methods..
}
있습니다 : Unluckly 나는 사람 안에 내가 코드
완전히 Person 객체의 내부에 있다는 것을 모든 속성을 얻을 수 없습니다 positionSet를 직렬화 할 때 사람 일대 다 Many Position OneTouchUnit Position에는 OrganizationUnit을 참조하는 "positionType"및 "organizationUnit"속성이 있습니다. jaxb serialize 할 때 position 유형 요소와 Position 내에있는 organizationUnit 요소에 대한 것만 볼 수 있습니다. Position에 값이 들어 있는지 확인하려고했는데 데이터가 객체 내부에서 사용 가능하다는 것을 알았습니다. PositionType 내부의 positionType과 organizationUnit 속성의 차이점은 positionUnit에이 주석이 필요하지 않지만 OrganizationUnit 클래스에 의해 매핑 된 organizationUnit 속성에 필요한 @XmlInverseReference 주석입니다.
어떻게이 문제를 해결할 수 있습니까? 특수 효과로 인해 조직 내 위치에 액세스 할 수없는 이유는 무엇입니까?
누군가가 나를 도울 수 있기를 바랍니다. 단순히 위치 내부 organizationUnit 속성에 주석 @XmlInverseReference을 제거하여 해결
<person>
// other property
<position-set>
<position>
<id>174215</id>
<discriminator>support</discriminator>
<endDate>2005-06-30T00:00:00</endDate>
<organizationUnitId>1234</organizationUnitId>
<positionType>
<id>2733</id>
<displayValue>BLABLA</displayValue>
<organization-unit-type>
<id>101</id>
<description>supportRole</description>
</organization-unit-type>
</positionType>
<startDate>2005-02-01T00:00:00</startDate>
</position>
</position-set>
This is the oxm file:
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="it.mymodel.ga.model" >
<xml-schema
element-form-default="QUALIFIED"/>
<java-types>
<java-type name="Person" xml-accessor-type="NONE">
<xml-root-element/>
<java-attributes>
<xml-element java-attribute="firstName" name="first-name" />
<xml-element java-attribute="lastName" name="last-name" />
<xml-element java-attribute="stringMap" name="string-map" />
<xml-element java-attribute="positionSet" name="position" >
<xml-element-wrapper name="position-set"/>
</xml-element>
</java-attributes>
</java-type>
<java-type name="Position"> <!-- I had to use this approach than xml-accessor-type="NONE" unlikely -->
<java-attributes>
<xml-element java-attribute="discriminator" />
<xml-element java-attribute="startDate" />
<xml-element java-attribute="endDate"/>
<xml-element java-attribute="organizationUnit" name="organization-unit"/>
<xml-element java-attribute="positionType" name="position-type"/>
<xml-transient java-attribute="person"/>
<xml-transient java-attribute="positionTypeId"/>
<xml-transient java-attribute="fileInfo"/>
<xml-transient java-attribute="personId"/>
<xml-transient java-attribute="priority"/>
<xml-transient java-attribute="uniqueIdentifier"/>
<xml-transient java-attribute="uuid"/>
<xml-transient java-attribute="removeFile"/>
</java-attributes>
</java-type>
<java-type name="OrganizationUnit">
<java-attributes>
<xml-transient java-attribute="description" name="description" />
<xml-element java-attribute="organizationUnitType" name="organization-unit-type"/>
<xml-transient java-attribute="displayAs"/>
<xml-transient java-attribute="organizationUnitTypeId"/>
<xml-element java-attribute="displayValue" />
</java-attributes>
</java-type>
<java-type name="OrganizationUnitType" >
<java-attributes>
<xml-element java-attribute="description"/>
<xml-transient java-attribute="priority"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>