0 Replies Latest reply on May 15, 2014 3:14 PM by noamichael

    Problems with Custom Schema (Duplicate persist calls)


      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 {



          private String loginName;



          private String firstName;



          private String lastName;



          private String email;



          private String phoneNumber;



          private String theme = "home";



          private Integer loginAttempts;



          @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:




          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?