我有一个现有的模型并希望将它与 Picketlink 一起使用。但我使用 Long 作为@Id
字段。但Picketlink 期望这是一个字符串字段。我发现了一些使用另一个实体的提示,该实体映射到我的模型的相应实体。但实际上我现在不知道该怎么做。
我有一个基类,所有实体都派生自:
@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);
}
}
});
当我尝试创建一个新的领域时,Hibernate 在尝试加载领域时抛出一个错误,因为它@Id
被定义为 Long,但@Identifier
Picketlink 模型的 是一个字符串。
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?