具有自定义模型和长ID的Picketlink

时间:2018-01-18 12:54:50

标签: jpa java-ee picketlink

我有一个现有的模型,并希望将它与Picketlink一起使用。但是我使用Long作为@Id字段。但是Picketlink希望这是一个String字段。我找到了一些使用另一个实体的提示,该实体映射到我的模型的相应实体。但实际上我现在不怎么做。

我有一个基类,所有实体都来自:

@MappedSuperclass
public abstract class AbstractEntity implements Serializable, Cloneable {
    @Id
    @Identifier
    @Column(name = "SID")
    private Long sid;

    @Column(name = "INSERT_TIME")
    private Date insertTime;

    @Column(name = "UPDATE_TIME")
    private Date updateTime;

    // getters and setters
}

派生的领域实体:

@Entity
@IdentityManaged(Realm.class)
public class RealmEntity extends AbstractEntity {
    @AttributeValue
    private String name;

    @PartitionClass
    private String typeName;

    @ConfigurationName
    private String configurationName;

    @AttributeValue
    private boolean enforceSSL;

    @AttributeValue
    private int numberFailedLoginAttempts;

    // getters and setters
}

Picketlink的映射类如下所示:

@IdentityPartition(supportedTypes = {
    Application.class,
    User.class,
    Role.class
})
public class Realm extends AbstractPartition {
    @AttributeProperty
    private boolean enforceSSL;

    @AttributeProperty
    private int numberFailedLoginAttempts;

    private Realm() {
        this(null);
    }

    public Realm(String name) {
        super(name);
    }
}

PartitionManager的定义如下:

builder
    .named("default.config")
    .stores()
    .jpa()
    .supportType(User.class, Role.class, Application.class, Realm.class)
    .supportGlobalRelationship(Grant.class, ApplicationAccess.class)
    .mappedEntity(App.class, AppUserRole.class, AppRole.class, AppUser.class, UserEntity.class, RelationshipIdentityTypeEntity.class, RealmEntity.class)
    .addContextInitializer((context, store) -> {
        if (store instanceof JPAIdentityStore) {
            if (!context.isParameterSet(JPAIdentityStore.INVOCATION_CTX_ENTITY_MANAGER)) {
                 context.setParameter(JPAIdentityStore.INVOCATION_CTX_ENTITY_MANAGER, entityManager);
            }
        }
    });

当我尝试创建新的Realm时,Hibernate在尝试加载Realm时会抛出错误,因为@Id被定义为Long,但Picketlink模型的@Identifier是一个String。

this.shsRealm = new Realm(REALM_SHS_NAME);
this.shsRealm.setEnforceSSL(true);
this.shsRealm.setNumberFailedLoginAttempts(3);

this.partitionManager.add(this.shsRealm);
  

java.lang.IllegalArgumentException:为类de.logsolut.common.picketlink.model.RealmEntity提供了错误类型的id。预期:类java.lang.Long,得到类java.lang.String

如何正确地将JPA模型映射到Picketlink?

0 个答案:

没有答案