tehAnswer
tehAnswer

Reputation: 1018

How can I map double relationships JPA?

I need map at JPA something like this:

https://i.sstatic.net/9ve1W.png

How I can map two relationships between two "tables", one of them is primary key and one to one (newClient in advance) and in the other side, a one to many that aint PK?

I tried something like this but it fails.

public class Recommendation implements Serializable {
    @Id @OneToOne
    @Column(name="...")
    private Client newClient;
    @ManyToOne
    @Column(name="...")
    private Client oldFella;
    @Column(name="...")
    private Boolean wasUsedToGenerateBond;

...

}

Thanks!

Upvotes: 0

Views: 1021

Answers (2)

user2860053
user2860053

Reputation:

it is possible to have multiple ManyToMany relationships between two entities. Each relationship would have its own join table. The default name of the join table may be the same, so you would need to specify the @JoinTable's name.

possible answer here

JPA Problems mapping relationships

more information

Hibernate 4.2, bidirectional @OneToOne and @Id

Upvotes: 1

Andrei Nicusan
Andrei Nicusan

Reputation: 4623

Like this:

@Id @OneToOne
@JoinColumn(name="id_client1")
private Client newClient;
@ManyToOne
@JoinColumn(name="id_client2")
private Client oldFella;

Upvotes: 0

Related Questions