我尝试实施有限类型的对象级ACL,并将其引导到我试图使用具有常量和动态的复合键创建@OneToOne
关系的位置值。
我有一个实体,其数据库ID和类中定义的常量值。
public class Entity{
private static final int objectType = 1;
@Id
Integer id;
}
我有一个access_levels
表,其复合键为objectId
和objectType
。
public class AccessLevel {
@EmbeddedId
private AccessLevelKey accessLevelKey;
@Embeddable
class AccessLevelKey implements Serializable{
private Integer objectType;
private Integer objectId;
....
}
}
access_levels
CREATE TABLE access_levels(
object_type INTEGER NOT NULL,
object_id INTEGER NOT NULL,
....
CONSTRAINT access_levels_type_id PRIMARY KEY (object_type, object_id)
);
我尝试提出Entity
可以用来获取和更新其关联的AccessLevel
看了Non-Standard Joins上的文档,我觉得我需要这样的东西,
实体内部:
@OneToOne
@JoinColumns({
@JoinColumn(name = "id", referencedColumnName = "object_id"),
@JoinColumn(name = "access_levels.object_type", referencedColumnName = "1"),
})
private AccessLevel accessLevel;
然而,这会在应用启动时抛出一个休眠MappingException
Caused by: org.hibernate.MappingException: Unable to find column with logical name: 1 in access_levels
谢谢!