在Java中使用此Person实体:
@Data
@Entity
@NoArgsConstructor
@XmlRootElement(name="Person")
@XmlAccessorType(XmlAccessType.FIELD)
public class Person implements Serializable {
@EmbeddedId
private PersonIdentity persondentity;
private String name;
private Boolean active;
private Boolean closed;
@XmlJavaTypeAdapter(DateAdapter.class)
@XmlAttribute(name = "DateBirth")
private Date birth;
@XmlAttribute(name = "PersonName")
private String personaName;
}
和PersonIdentity,它的作用类似于复合键:
@Data
@NoArgsConstructor
@Embeddable
public class PersonIdentity implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Long id;
@XmlAttribute(name = "PersonId")
private String personId;
}
我试图将这样的XML映射到Person类:
<?xml version="1.0" encoding="UTF-8"?>
<Person personId="2017PIOE-A132" PersonName="John" DateBirth="19Apr2018 18:53" />
在开始时,没有复合键(@EmbeddedId),我能够映射对象,现在使用PersonIdentity作为主键,我可以映射其他属性但不是这个,我做错了什么?