RPr*_*sle 5 java inheritance hibernate
我有两个具有继承关系的实体,即内容和图像。继承策略为JOINED。当我插入图像时,它会执行3个查询:在Content表中插入,在Image表中插入,然后更新Content表。所有更新的值都等于插入的值(不做任何实际修改)
有什么线索吗?
@Entity
@Table(name = "content")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "content_type", discriminatorType = DiscriminatorType.STRING, length = 255)
public class Content {
@Id
@SequenceGenerator(name = "content_id_sequence_generator", sequenceName = "content_id_sequence", allocationSize = 1)
@GeneratedValue(strategy = SEQUENCE, generator = "content_id_sequence_generator")
private Long id;
@Column(name = "locale")
private String locale;
}
@Entity
@Table(name = "image")
public class Image extends Content {
@Column(name = "credit")
private String credit;
}
Run Code Online (Sandbox Code Playgroud)
当我执行CRUDRepository.save(image)时:
insert
into
pfu.content(locale, id) values('en', 1000)
insert
into
pfu.image(credit, id) values('author', 1000)
update
pfu.content
set locale='en' where id=1000
Run Code Online (Sandbox Code Playgroud)
一切都在一个事务中完成,并且我不修改已保存对象中的任何内容。请注意,我猜它与继承有联系,但这只是一个猜测
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |