Hello!
I don't know whether I am posting my thread in the right place or no. If I am not, let me know.
I am starting with JPA but I found a problem with @ManyToOne relation when the foreign key is part of the primary key.
Here is my database:
[b]Table Client[/b]
cli_id_client (PK)
[b]Table Card[/b]
cli_id_card (PK)
[b]Table ClientCard[/b]
cli_id_client (PK)
cli_id_card (PK)
Those are my entities:
public class [b]ClientCard[/b]{
@Id
@Column(name = "car_id_card")
private int idCard;
@Id
@Column(name = "cli_id_client")
private int idClient;
@ManyToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumns({_at_PrimaryKeyJoinColumn(name = "car_id_card", referencedColumnName = "car_id_card")})
private Card card;
@ManyToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumns({_at_PrimaryKeyJoinColumn(name = "cli_id_client", referencedColumnName = "cli_id_client")})
private Client client;
}
public class [b]Client[/b]{
..
@Id
@Column(name = "cli_id_client")
private int idClient;
@OneToMany(mappedBy="Client")
private java.util.List<ClientCard> listClientCard;
}
public class [b]Card[/b]{
..
@Id
@Column(name = "car_id_card")
private int idCard;
@OneToMany(mappedBy = "card")
private java.util.List<ClientCard> listClientCard;
}
Unfortunately, when I try persist the ClientCard, I receive the message:
08:21:22,711 WARN [JDBCExceptionReporter] SQL Error: 207, SQLState: S0022
08:21:22,711 ERROR [JDBCExceptionReporter] [HOST]Invalid column name 'card_car_id_card'.
08:21:22,711 WARN [JDBCExceptionReporter] SQL Error: 207, SQLState: S0022
08:21:22,711 ERROR [JDBCExceptionReporter] [HOST]Invalid column name 'client_cli_id_client'.
Am I missing any configuration?
[Message sent by forum member 'danilorocha']
http://forums.java.net/jive/thread.jspa?messageID=485747