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
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:
Post a Comment