Hello!
I'm trying to implement my own Hibernate NamingStrategy based on the ImprovedNamingStrategy. This is quite nice... only the foreign keys of many-to-many relations are ugly.
Example scenario:
public class Teacher {
@ManyToMany
private Set<Course> courses;
}
public class Course {
@ManyToMany
private Set<Teacher> teachers;
}
With my custom naming stratgy
public class MyImprovedNamingStrategy extends ImprovedNamingStrategy {
private static final long serialVersionUID = 1L;
@Override
public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) {
String s = super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName);
return s.endsWith("_id") ? s : s + "_id";
}
}
this would lead to a table teachers_courses with the columns teachers_id, courses_id.
What i try to realize is a table named teacher_course with the fields teacher_id, course_id. Any suggestions, how to sugularize my pluralized named properties of the entities?
Thanks in advance