views:

33

answers:

1

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);
    }
}
+1  A: 

Either #{newUserController.group} or #{newUserController.group.groupKey} returned null. JSF will only set the last property (which is groupId in this case). If this is a template entity, you need to provide/preset a default and non-null value for group and/or groupKey. If this is an existing entity, you need to ensure that those properties are properly prepopulated by JPA.

BalusC