Hi all,
I am having troubles to map a bidirectional many-to-one association with a Join table?
Code:
public class A {
....
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch=FetchType.LAZY, targetEntity=B.class)
@JoinTable(
name="A_B",
joinColumns=@JoinColumn(name="A_ID"),
inverseJoinColumns=@JoinColumn(name="B_ID")
)
@IndexColumn(name = "position", base=0)
private B b;
...
}
public class B {
...
@OneToMany(mappedBy="b", fetch = FetchType.LAZY, targetEntity=A.class)
private List<A> myList = new ArrayList<A>();
...
}
I have a SQLGrammarException: Could not load an entity A
If I take a look at the sql generated, I can see that the JOIN is not done and that the inverseColumn column is used in the select clause:
Code:
select
...
b0_.[color=red]B_I[/color]D as B2_24_0_
from
B b0_
....
This means that the joinTable annotation is ignored and Hibernate thinks that an entity A is linked to an entiy B via the foreign key B_ID.....
I do not understand where is the mistake in my mapping.......
Thanks for your help,
tiggy