I had the weirdest bug the other day. I was creating a data model for a Java application using JPA and Hibernate as provider.
I was implementing a many-to-one-relationship. Even though I'm no pro at JPA, I never experienced big trouble. Until now. Suddenly, my relations did not turn out in the database model I expected. Instead of creating a foreign key, I always had a tinyblob field. The relevant parts of the class were something like:
protected FinanceProfile financeProfile;
// ...
@ManyToOne
public void setFinanceProfile(FinanceProfile financeProfile) {
this.financeProfile = financeProfile;
}
public FinanceProfile getFinanceProfile() {
return financeProfile;
}
I tried to use this class, but always received an error like:
org.hibernate.exception.DataException: could not insert [com.mypackage.model.FinanceAccount][SQL: 0, 22001]
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'finance_profile' at row 1
Now, do you see the error? Because... well, I didn't. Took me several hours to figure it out. The culprit is... tadaa... I had switched the order of the getter/setter-methods. Well, Eclipse did this for me, and I didn't check. After I changed the order of the two methods (and put the annotation above the getter), everything was ok.
I think I should start annotating the members themselves. That way, this won't happen again (at least I hope so).