开发者

Jointable with three columns

开发者 https://www.devze.com 2023-02-15 19:09 出处:网络
I want to create the following mappings in JPA-2.0 using Hibernate 3.6 and MySQL 5.1: Table \"PIPE\" ------------

I want to create the following mappings in JPA-2.0 using Hibernate 3.6 and MySQL 5.1:

Table "PIPE"
------------
pipe_id (PK)
============
pipe_name
pipe_modified_date
------------


Table "ALGO"
------------
algo_id (PK)
============
algo_name
------------

The table "Pipe" can store multiple algos (many-to-many between "Pipe" and "Algo"). It is important to store the order index of the list too. It should be also possible to store the sa开发者_JAVA百科me algo more than once.

How to model the appropriate jointable with a composite primary key consisting of three columns?

Table "PIPE_ALGO_JT"
---------------------
order_index (PK)
pipe_id (FK PK)
algo_id (FK PK)
=====================
---------------------


@OrderColumn should do exactly what you want:

@Entity
public class Pipe {
    @ManyToMany
    @JoinTable(name = "PIPE_ALGO_JT")
    @OrderColumn(name = "order_index")
    private List<Aglo> algos;

    ...
}

Though in schema generated by Hibernate primary key would consist of pipe_id and order_index (since having algo_id in primary key is redundant in this case).

0

精彩评论

暂无评论...
验证码 换一张
取 消