我希望实体的@OneToOne
字段是懒惰的(通过字节码增强),而代理的实例是@OneToMany
是惰性的。
@Entity
@Table(name = "CLIENTS")
class Client {
@Id
@Column(name = "CLIENT_KEY")
@GeneratedValue(generator = "triggerAssigned")
private Long key;
@JoinColumn(name = "CLIENT_TYPE_KEY", referencedColumnName = "TYPE_KEY", nullable = false)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private ClientType clientType;
@Fetch(value = FetchMode.JOIN)
@OneToOne(mappedBy = "client")
@LazyToOne(value = LazyToOneOption.NO_PROXY)
private ClientAddress clientAddress;
}
@BatchSize(size = 100)
@Entity
@Table(name = "CLIENT_ADDRESS")
class ClientAddress {
@Id
Long key;
@MapsId
Client client;
}
@Entity
@Table(name = "CLIENT_TYPE")
@BatchSize(size = 100)
class ClientType {
@Id
@GeneratedValue(generator = "triggerAssigned")
@Column(name = "TYPE_KEY")
private Long key;
}
当我查询有关Client的信息时,我希望ClientType是代理并被懒惰地检索。但是休眠时逐行选择Client + ClientType(n + 1问题)。似乎忽略了两个BatchSize批注。我尝试将@LazyToOne
注释放在clientType字段上,但更糟的是:CLIENT_TYPE_KEY
列被延迟查询,然后ClientType被查询n次。
您知道休眠字节码增强功能是否可以与代理和传统的延迟加载一起使用?