在我的 JSF 里面我做了
<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
}
所以当我尝试持久化对象时,它给了我这个错误
value="#{newUserController.group.groupKey.groupId}": Target Unreachable, 'null' returned null
编辑
这是我的托管 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);
}
}