如何映射实体和组件

时间:2012-07-15 09:02:34

标签: hibernate

我有一个实体Note和component FavoriteNote,这里是表定义:

CREATE TABLE NOTE (
  ID INTEGER,
  TITLE VARCHAR(100) CHARACTER SET UTF8,
  CONTENT BLOB SUB_TYPE 1 CHARACTER SET UTF8,
  TYPE_NO INTEGER,
  DEL SMALLINT,
  CREATE_DATE TIMESTAMP,
  UPDATE_DATE TIMESTAMP);

CREATE TABLE FAVORITE (
  NOTE_NO INTEGER NOT NULL,
  DROP_IN_DATE DATE);

和java代码是:

public class FavoriteNote {
    private Note note;
    private Date dropInDate;

    public Note getNote() {
        return note;
    }

    public void setNote(Note note) {
        this.note = note;
    }

    public Date getDropInDate() {
        return dropInDate;
    }

    public void setDropInDate(Date dropInDate) {
        this.dropInDate = dropInDate;
    }
}

public class Note implements Serializable {
    private static final long serialVersionUID = -8363339156398741610L;
    private int id;
    private String title;
    private String content;
    private String typeName;
    private int del;
    private int show;
    private NoteType noteType;
    private BeanState beanState;
    private Date createDate;
    private Date updateDate;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }


    public int getDel() {
        return del;
    }

    public void setDel(int del) {
        this.del = del;
    }

    public int getShow() {
        return show;
    }

    public void setShow(int show) {
        this.show = show;
    }

    public NoteType getNoteType() {
        return noteType;
    }

    public void setNoteType(NoteType noteType) {
        this.noteType = noteType;
    }


    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }


    public BeanState getState() {
        return beanState;
    }

    public void setState(BeanState beanState) {
        this.beanState = beanState;
    }

    @Override
    public String getClassName() {
        return "Note";
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }
}

问题是FavoriateNote不是Note的一部分,它们只是一对一的关联。如何配置关联以便检索所有FavoriteNotes?最好以xml方式完成。

由于

0 个答案:

没有答案