java在更改实体中的PropertyT时,不会使用cascade=“alldeleteorphan”更改对集合的引用
当我试图更改实体(而不是集合)中某个属性的值时,出现了上述异常
我通过tinyUrl检索值,尽管它不是表中的主键
下面是代码片段的一部分
Sample sample = retrieveContentByUrl("https://text.com");
sample.setDescription("Sample");
getSession().saveorupdate(sample);
样品。爪哇
class Sample {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ID")
private int id;
@Column(name="TINY_URL")
private int tinyUrl;
@Column(name="DESCRIPTION")
private String description;
@OneToMany(mappedBy="sample",fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
private Set<TextBooks> textBooks = new HashSet<TextBooks>();
//Having getters and setters for all above variables
}
教科书。爪哇
class TextBooks {
@ManyToOne
@JoinColumn(name = "ID")
private Sample sample;
//Having getters and setters for all above variables
}
。hbm文件
<class name="com.sample.Sample"
table="SAMPLE" >
<id name="id" column="ID" type="long">
<generator class="identity" />
</id>
<property column="TINY_URL" name="tinyUrl" />
<property column="DESCRIPTION" name="description" />
<set name="textBooks" inverse="true" cascade="all-delete-orphan">
<key column="ID" />
<one-to-many
class="com.text.TextBooks" />
</set>
</set>
</class>
共 (0) 个答案