ich einen nächsten drei Tabellen (PostgreSQL) haben:JPA ManyToMany Mapping mit zusätzlichen Feldern
CREATE TABLE boards (
id SERIAL PRIMARY KEY,
....
);
CREATE TABLE IF NOT EXISTS cards (
id SERIAL PRIMARY KEY,
name VARCHAR(256),
description TEXT,
...
);
CREATE TABLE IF NOT EXISTS boards_cards(
board_id INTEGER,
card_id INTEGER,
on_hold BOOLEAN DEFAULT FALSE,
CONSTRAINT pk_user_card PRIMARY KEY (board_id, card_id),
FOREIGN KEY(board_id) REFERENCES boards(id),
FOREIGN KEY(card_id) REFERENCES cards(id)
);
und einer folgenden JPA Entities:
@Entity
@Table(name = "boards")
public class Board extends BaseEntity implements Serializable {
@Id
@SequenceGenerator(name = "boards_id_seq", sequenceName = "boards_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "boards_id_seq")
private Long id;
@Entity
@Table(name = "cards")
public class Card extends BaseEntity implements Serializable {
@Id
@SequenceGenerator(name = "cards_id_seq", sequenceName = "cards_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "cards_id_seq")
private Long id;
private String name;
private String description;
Wie man richtig Zuordnungen organisieren, um der Lage sein, get boards_cards.on_hold
für eine bestimmte Card
, die Board
über ManyToMany
Beziehung über boards_cards
Tabelle zugeordnet ist?
chceck dies heraus http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/ – mariusz2108
marginally verwandt, aber mit IDENTITY Sequenzgenerator funktioniert in pg und macht die Dinge einfacher –
@ Niel-McGuigan Identität erlaubt keine Vorabzuweisung und hat andere Nachteile - wie macht es das Ding leichter? https://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Identity_sequencing – Chris