Forgive my ignorance, but i've been trying to google/yahoo this thing for 2 days in a row already.
Hope you can shed me some light.
I have these database objects/tables below:
As you can see i have issuingbank table with a child table bankaccount with a onetomany relationship (wrt to issuingbank).
bankaccount.bankcode has a foreign key defined that references to issuingbank.bankcode.
I did my Hibernate Annotation mapping below:
When I try to load all issuingbank data EAGERLY using getHibernateTemplate.loadAll(IssuingBank.class),
I was able to load all IssuingBank data, and only some BankAccount data, even though the FETCHTYPE is EAGER. Further investigation (or maybe I am wrong),
is that I noticed that all data with issuingbank.bankcode value parsable to Integer are loaded, while all data with issuingbank.bankcode value not parsable to integer were not loaded.
ANd when I try to load all BankAccount using getHibernateTemplate(BankAccount.class), I get and exception:
Caused by: java.sql.SQLException: Invalid value for getInt() -
It tried accessing all bankcode value as an int, but since it cant be cast it's an error.
Why did it tried to access the value via getInt() when in fact in the database it is varchar? Have I done something wrong in my map?
Also, how come the generated query is like this:
it tried to join via bankaccount.bankcode and issuingbank.id; i have explicitly define that the mapping should be issuingbank.bankcode to bankaccount.bankcode.
I would be very glad if you tell me what I've don wrong.
posted 10 years ago
Im using Hibernate, Spring Struts (Using Hibernate Annotation), on MySQL 5.1 RDBMS.
my foreign key bankaccount.bankcode references to issuingbank.bankcode which is not a primary key, but a unique key.
(i think the above is the caused of the problem since the primary key of issuingbank is an integer; explains the getInt() part,
but i dont know why)
posted 10 years ago
i think i found the answer. i dont know why but adding referenceColumn name inside @JoinColumn annotation solves the problem.