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 {
privat开发者_C百科e 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?
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.
精彩评论