0

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?

Çağdaş
  • 993
  • 1
  • 12
  • 33

1 Answers1

0

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.

Thomas
  • 87,414
  • 12
  • 119
  • 157
  • Thanks for response. We solved this issue with assigning persisted tag to current deal. And then persist. I think it is all about bussiness logic. But it makes me to think is it too hard to annotate entities for this use case? :) – Çağdaş Sep 19 '11 at 20:37