I'm am currently using PicketLink in a enterprise application. I just began writing my custom schema and have faced some interesting issues. All the entities from the jpa-quickstart schema are present in my project, but I have added an additional AccountEntity which extends IdentityTypeEntity:
public class CustomAccountEntity extends IdentityTypeEntity {
@AttributeValue
private String loginName;
@AttributeValue
private String firstName;
@AttributeValue
private String lastName;
@AttributeValue
private String email;
@AttributeValue
private String phoneNumber;
@AttributeValue
private String theme = "home";
@AttributeValue
private Integer loginAttempts;
@AttributeValue
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "address_fk")
private Address address;
//Getters, Setters
The issue is when I go to add or update a custom user, PicketLink tries to update it twice. In JPAIdentityStore, I found the following code:
@Override
public void updateAttributedType(IdentityContext context, AttributedType attributedType) {
EntityManager entityManager = getEntityManager(context);
for (EntityMapper entityMapper : getMapperFor(attributedType.getClass())) {
entityMapper.updateEntity(attributedType, entityManager);
}
}
The issue is that getMapperFor() returns two entities for my custom account class: CustomAccountEntity, which is correct, and IdentityTypeEntity, which is also technically correct because the account is also an identity type. The Address entity that is stored in my CustomAccountEntity has a unique constraint on it's ID which becomes violated on the second call to EntityManager.persist(). The interesting thing is, this problem does not occur to GroupType or RoleType entities, both of which extend IdentityTypeEntity. There must be something I'm missing, any ideas? One final question, why do you use persist() when updating an entity and not merge?
-Michael