我想在JPA-2.0中使用Hibernate 3.6和MySQL 5.1创建以下映射:
Table "PIPE"
------------
pipe_id (PK)
============
pipe_name
pipe_modified_date
------------
Table "ALGO"
------------
algo_id (PK)
============
algo_name
------------表“管道”可以存储多个算法(“管道”和“算法”之间的多对多)。存储列表的顺序索引也很重要。还应该可以多次存储相同的算法。
如何使用由三列组成的复合主键对适当的连接表进行建模?
Table "PIPE_ALGO_JT"
---------------------
order_index (PK)
pipe_id (FK PK)
algo_id (FK PK)
=====================
---------------------发布于 2011-03-10 17:01:28
@OrderColumn应该完全按照您的要求进行操作:
@Entity
public class Pipe {
@ManyToMany
@JoinTable(name = "PIPE_ALGO_JT")
@OrderColumn(name = "order_index")
private List<Aglo> algos;
...
}尽管在Hibernate生成的模式中,主键将由pipe_id和order_index组成(因为在这种情况下,在主键中使用algo_id是多余的)。
https://stackoverflow.com/questions/5257323
复制相似问题