如果未插入儿童实体,如何级联
我们目前正在使用接缝框架。我们在注释实体方面有一些麻烦。我们有一个具有标签实体孩子的交易实体。我们注释实体如下;
@Entity
public class Deal implements Serializable {
private Tag tag;
@ManyToOne
public Tag getTag() {
return tag;
}
public void setTag(Tag tag) {
this.tag = tag;
}
}
标签实体就像;
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = "label") })
public class Tag implements Serializable {
private String label;
public void setLabel(String tagLabel) {
this.label = tagLabel;
}
public String getLabel() {
return label;
}
}
用例是;我们有默认值用于标记交易。用户通过AutoCompleter输入框搜索标签。如果没有匹配,他/她键入自己的免费标签。当他/她坚持交易实体时,如果db中没有存储标签,则将持续存在标签实体,否则引用存储的标签实体来交易实体。
我们可以注释符合此用例的实体吗?还是关于业务逻辑的全部?
We are currently using seam framework. And we have a little trouble with annotating entities. We have a Deal entity that has a Tag entity child. We annotated entities as following;
@Entity
public class Deal implements Serializable {
private Tag tag;
@ManyToOne
public Tag getTag() {
return tag;
}
public void setTag(Tag tag) {
this.tag = tag;
}
}
And the tag entity is like;
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = "label") })
public class Tag implements Serializable {
private String label;
public void setLabel(String tagLabel) {
this.label = tagLabel;
}
public String getLabel() {
return label;
}
}
Use case is; we have default values to tag deals. User searches a tag by autocompleter inputbox. If no match, he/she types own free tag. When he/she persists Deal entity, Tag entity would be persisted if there is no tag stored in DB, else reference stored tag entity to deal entity.
Can we annotate entities that conforms this use case? Or all about the business logic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 没有直接的方法来使用这样的级联。
您需要分配一个具有正确 id 的实体,方法是查找实体或创建一个获取 id 但不级联的新实体。
AFAIK there's no direct way to use cascade like this.
You need to assign an entity that has the correct id, either by looking it up or by creating a new one that gets the id but is not cascaded.