hibernate 多表关联如何使用注解配置

@Entity

@Table(name = "COURSE")

@JsonIgnoreProperties(ignoreUnknown = true)

public class BasePassengerStation implements Serializable {

        ......//其他属性,省略

        //多表关联

        @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH }, optional = false)

@JoinColumn(name = "courseStudentId", referencedColumnName = "studentId", insertable = false, updatable = false)//相关联的两个表中管理字段名字不一致时,用referencedColumnName指定关联表的字段名

@NotFound(action = NotFoundAction.IGNORE)//如果属性值为某某的数据在数据库中不存在时,不让hibernage抛出异常,忽略该异常

private STUDENT student;

@Transient//属性为短暂的,不会持久化到数据库

private String rtBisOwnerInfoOwnerName;

......

}

相关推荐