Skip to content

Instantly share code, notes, and snippets.

@gaol
Created January 14, 2013 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaol/4528002 to your computer and use it in GitHub Desktop.
Save gaol/4528002 to your computer and use it in GitHub Desktop.
@Entity
@Table(name = "Affected_Product")
public class AffectedProduct implements Serializable{
@Id
@GeneratedValue
private Long id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "product", cascade = {CascadeType.ALL})
@JoinTable
private Collection<LinkData> fixLocations;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "product", cascade = {CascadeType.ALL})
private Collection<LinkData> brewLinks;
}
@Entity
@Table(name = "link_data")
public class LinkData implements Serializable{
@Id
@GeneratedValue
private Long id;
@Column
private String type;
@ManyToOne
@JoinColumn(name = "affected_product_id", referencedColumnName = "id")
private AffectedProduct product;
}
// 这里除了 affected_product_id 这个字段外,还想使用 type 的值。
// 比如: type=brew 的时候, 对应的是 brewLinks 列表
// type= fixlocation 的时候, 对应的是 fixLocation 列表
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment