我有两个表如下。
create table A(id int, type char(1), desc varchar(32))
create table B(id int,
aId1 int not null,
aId2 int null,
mapDefName varchar(11))
在表B中,记录需要从表A中引用两个ID,而AID1不是null的表A,并且在插入过程中,AID2列可能为null。但是这些AID1和AID2列不能是PK。
tablea的记录类型列值为" x",需要映射到tableb:aid1列。
tablea的记录类型列值为" y",需要映射到tableb:aid2列。
例如;
Table A;
id type desc
---- ---- -----
12 x something...
13 y something...
14 x something...
15 y something...
16 x something...
17 y something...
Table B;
id aId1 aId2 mapDefName
---- ---- ----- ----------
1 12 13 sth...
2 12 13 sth...
3 12 sth...
4 14 sth...
5 14 sth...
6 14 15 sth...
7 16 17 sth...
8 16 17 sth...
如何用冬眠的注释编码此映射?
谢谢,
冬眠注释 - 滤波器
和示例
在您的情况下,您应该定义tablea:
@Entity
@Table(name="TableA")
@FilterDef(name="studentFilter", parameters={
@ParamDef(name="type", type="string" )
})
@Filters( {
@Filter(name="idFilter", condition="type = :type")
} )
public class TableA{
...
}
然后使用session enablefilter((
Filter filter = session.enableFilter("studentFilter");
filter.setParameter("type", "x");
session.disableFilter("studentFilter");
我以前没有使用过此功能,只是一些指南。希望它有帮助。