UserGroup extends GeonetEntity implements Serializable { @Override protected Element asXml(IdentityHashMap<Object, Void> alreadyEncoded) { return new Element("record") .addContent(new Element("group").setText("" + getId().getGroupId())) .addContent(new Element("user").setText("" + getId().getUserId())) .addContent(new Element("profile").setText(getProfile().name())); }  @EmbeddedId UserGroupId getId(); UserGroup setId(UserGroupId id); @MapsId("groupId") @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "groupId", referencedColumnName = "id") Group getGroup(); UserGroup setGroup(Group group); @MapsId("userId") @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId", referencedColumnName = "id") User getUser(); UserGroup setUser(User user); @Transient Profile getProfile(); UserGroup setProfile(Profile profile);  }
@Test public void testAsXml() throws Exception { final Group group = new Group().setId(1); final User user = new User().setId(2); final UserGroup userGroup = new UserGroup().setGroup(group).setUser(user).setProfile(Profile.Editor); final Element element = userGroup.asXml(); assertEquals("" + group.getId(), element.getChildText("group")); assertEquals("" + user.getId(), element.getChildText("user")); assertEquals(Profile.Editor.name(), element.getChildText("profile")); }