Pages

Thursday, December 18, 2008

the problem of strongly type language and very bad concept understanding

Well I've just solved another ridiculous problem with hibernate. And to save another poor soul that may have gone through the same path as I, I feel obligated to write this.

I'm trying to create a basic collection following this code example from hibernate annotation

@Entity public class City {
@OneToMany(mappedBy="city")
@OrderBy("streetName")
public List getStreets() {
return streets;
}
...
}

@Entity public class Street {
public String getStreetName() {
return streetName;
}

@ManyToOne
public City getCity() {
return city;
}
...
}

the problem is , in my modified code. I have TaskAction and TaskComment Class. Where TaskAction has Many TaskComment. And i write the mappedBy like this

@OneToMany(mappedBy="TaskAction")

since i thought java is strongly type and the mappedBy is used to show the relation of the mapped Class.

It turned out that this simple mistake cost me one day, luckily. thanks to this post, i found out that the mappedBy needs to refers to the field of Class that will be mapped.

so the mappedBy need to be written as "taskAction" not "TaskAction" or even "taskaction". And the mapping would look like this :

@OneToMany(mappedBy="taskAction")

where the taskAction is the field in TaskComment Class.

No comments: