简体   繁体   English

jaxb @ManyToMany @XmlID @XmlIDREF无法将Refed对象放入xml

[英]jaxb @ManyToMany @XmlID @XmlIDREF can't get the Refed objects into a the xml

Hi i have a problem when i use a webservice I have an object User that contains many Roles. 嗨,我在使用Web服务时遇到问题,我有一个对象User包含许多角色。

When i get one User(Id:3) from my webservice that contains a role and that role containes many users(id: 3 and id 2). 当我从Web服务中获得一个包含角色的User(Id:3)且该角色包含许多用户(ID:3和ID 2)时。 I got an error 我有一个错误

Caused by: javax.xml.bind.UnmarshalException: Undefined ID "2". 原因:javax.xml.bind.UnmarshalException:未定义的ID“ 2”。

I assume that this is due to the User with id 2 ain't in the xml. 我认为这是由于xml中没有ID为2的用户造成的。

My question is how do i get this user to be populated into the xml? 我的问题是如何使该用户填充到xml中?

@XmlRootElement()
public class User implements UserInterface {

    @Override
    @GeneratedValue
    @Id
    @XmlID
    @XmlJavaTypeAdapter(IntegerAdapter.class)
    public Integer getId() {
        return id;
    }

@Override
@ManyToMany(targetEntity=Role.class,fetch=FetchType.EAGER)
@XmlElement(type=Role.class)
public Set<RoleInterface> getRoles() {
    return roles;
}


}

@XmlRootElement()
public class Role implements RoleInterface {
    @ManyToMany(targetEntity=User.class,fetch=FetchType.EAGER)
    @XmlIDREF
    @XmlList
    public Set<UserInterface> getUsers() {
        return users;
    }
}

In order to use @XmlIDREF the referenced object must also be mapped through some sort of containment relationship such as @XmlElement . 为了使用@XmlIDREF ,还必须通过某种包含关系(例如@XmlElement来映射引用的对象。

For More Information 欲获得更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM