Dear all
When I specify multiple @JoinColumn's in an @JoinTable, I allways get a SQLException.
Following the relevant code extracts:
Code:
@XmlAccessorType(XmlAccessType.FIELD)
@Entity(name = "Rolle")
@Table(name = "ROLLE")
public class Rolle extends PassivateInformationEntity<String, String, String> {
// PK field is on superclass
...
@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
@JoinTable(name = "ROLLE_TEXT",
joinColumns = { @JoinColumn(table = "ROLLE", name = "FK_ROLLE_PK", referencedColumnName = "PK")},
inverseJoinColumns = { @JoinColumn(table = "TEXT_MEHRSPRACHIG", name = "FK_TEXT_MEHRSPRACHIG_PK", referencedColumnName = "PK"),
@JoinColumn(name = "LOCALE_COPY", referencedColumnName = "LOCALE") })
)
public Set<TextMehrsprachig> bezeichnungen;
...
Code:
@XmlAccessorType(XmlAccessType.FIELD)
@Entity(name = "TextMehrsprachig")
@Table(name = "TEXT_MEHRSPRACHIG")
public class TextMehrsprachig extends IdentificationInformationEntity<String> {
...
// PK field is on superclass
....
@Column(name = "LOCALE")
private Locale locale;
...
Calling the CrudRepository (Spring io)
Code:
T findOne(ID id);
method, results in the following SQL statement
Code:
select
rolle0_.PK as PK1_5_2_, rolle0_.FK_USERS_PK_CREATED_BY as FK_USERS2_5_2_, rolle0_.CREATION_DATE
as CREATION3_5_2_, rolle0_.FK_USERS_PK_LAST_MODIFIED_BY as FK_USERS4_5_2_, rolle0_.LAST_MODIFIED_DATE
as LAST_MOD5_5_2_, rolle0_.AKTIV as AKTIV6_5_2_, berechtigu1_.FK_ROLLE_PK as FK_ROLLE1_5_4_,
recht2_.PK as FK_RECHT2_6_4_, recht2_.PK as PK1_2_0_, recht2_.ID as ID2_2_0_, bezeichnun3_.FK_ROLLE_PK
as FK_ROLLE1_5_5_, textmehrsp4_.PK as FK_TEXT_2_7_5_, textmehrsp4_.PK as PK1_8_1_, textmehrsp4_.LOCALE
as LOCALE2_8_1_, textmehrsp4_.TEXT as TEXT3_8_1_
from
ROLLE rolle0_ left outer join ROLLE_RECHT berechtigu1_ on rolle0_.PK=berechtigu1_.FK_ROLLE_PK
left outer join RECHT recht2_ on berechtigu1_.FK_RECHT_PK=recht2_.PK
left outer join ROLLE_TEXT bezeichnun3_ on rolle0_.PK=bezeichnun3_.FK_ROLLE_PK
left outer join TEXT_MEHRSPRACHIG textmehrsp4_ on bezeichnun3_.FK_TEXT_MEHRSPRACHIG_PK=textmehrsp4_.PK and bezeichnun3_.LOCALE_COPY=textmehrsp4_.LOCALE
where
rolle0_.PK='UUID_62b95a09-79e6-11e3-9752-002c29dd52c2'
and throws afterwards the following exception:
Code:
2014-02-10 17:36:25, ID:10-05:36:24-905 - ERROR,jdbc.audit; 1. ResultSet.getString(LOCALE_C3_7_5_)
java.sql.SQLException: Column not found: LOCALE_C3_7_5_
at org.hsqldb.jdbc.Util.sqlException(Unknown Source) ~[hsqldb-2.2.9.jar:2.2.9]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source) ~[hsqldb-2.2.9.jar:2.2.9]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source) ~[hsqldb-2.2.9.jar:2.2.9]
at org.hsqldb.jdbc.JDBCResultSet.findColumn(Unknown Source) ~[hsqldb-2.2.9.jar:2.2.9]
at org.hsqldb.jdbc.JDBCResultSet.getString(Unknown Source) ~[hsqldb-2.2.9.jar:2.2.9]
at net.sf.log4jdbc.ResultSetSpy.getString(ResultSetSpy.java:2427) ~[log4jdbc4-1.2.jar:na]
If I remove the second @JoinColumn statement in the inverseJoinColumns all work fine...
Please let me know, if you need further infos.
Thanks for your help and best regards!