1

在我的基于 Hibernate Annotation 的应用程序中......我正在创建这样的表..

    CREATE  TABLE IF NOT EXISTS `EC_USER` (
  `S_ID` VARCHAR(30) NOT NULL PRIMARY KEY,
`CREATED_DATE` DATETIME NULL ,
`MODIFIED_BY` VARCHAR(30) NULL ,
 CONSTRAINT `CREATED_BY`
    FOREIGN KEY (`CREATED_BY` )
    REFERENCES `EC_USER` (`S_ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `MODIFIED_BY`
    FOREIGN KEY (`MODIFIED_BY` )
    REFERENCES `EC_USER` (`S_ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)

那么如何编写我的 Hibernate Bean ......

@Entity
@Table(name = "EC_USER")
public class UserVO{
@Id
@Column(name="S_ID")
private String id;
@Column(name = "CREATED_DATE")
private Date createdDate;
@Column(name = "LAST_MODIFIED_DATE")
private Date modifiedDate;
}

所以这是正确的一个或任何关系映射需要......

4

1 回答 1

4

假设您可以编写一个 CREATED_BY AND MODIFIED_BY 列

@Entity
@Table(name = "EC_USER")
public class UserVO{
@Id
@Column(name="S_ID")
private String id;
@Column(name = "CREATED_DATE")
private Date createdDate;
@Column(name = "LAST_MODIFIED_DATE")
private Date modifiedDate;

@ManyToOne
@JoinColumn(name="created_by")
private UserVO createdBy; 


@ManyToOne
@JoinColumn(name="modified_by")
private UserVO modifiedBy; 

}
于 2012-12-22T08:52:54.837 回答