Inside my JSF I did
<h:outputLabel value="Group:" for="group" />
<h:inputText id="group" value="#{newUserController.group.groupKey.groupId}" title="Group Id" />
Group.java
@Entity
public class Group {
@EmbeddedId
private GroupKey groupKey;
@ManyToOne
@JoinColumn(name="userId")
private User user;
//setter, getter, constructors, equals and hashes
}
GroupKey.java
@Embeddable
public class GroupKey {
@Column(name="userId", insertable=false, updatable=false)
private String userId;
private String groupId;
//setter, getter, constructors, equals and hashes
}
So when I try to persist the object, it give me this error
value="#{newUserController.group.groupKey.groupId}": Target Unreachable, 'null' returned null
EDIT
Here is the content of my Managed Bean.
@ManagedBean(name="newUserController")
@RequestScoped
public class NewUserController {
private User user = new User();
private Group group = new Group();
@EJB
DocumentSBean sBean;
public void createNewUser(){
user.addGroup(group);
sBean.persist(user);
}
}