Hibernation: more than one relationship using a single connection column

I am using an outdated compound key database schema. I have an entity with two relationships, and one of the join columns is shared.

For example, let them say that I have a student entity with two relations Department and Course. The department uses the dept_code column, while the course uses dept_code and code_path. The domain model is such that a student can belong to a department, but did not choose a course, or a student could choose both a department and a course. This is how sleep mode looks:

             

<many-to-one class="Department" name="department">
  <column name="dept_code"/>
</many-to-one>

<many-to-one class="Course" name="course>
  <column name="dept_code"/>
  <column name="course_code"/>
</many-to-one> 

The problem is that Hibernate does not allow this mapping if one of the relationships is not checked only with insert = false and update = false.

Is there a way that both relationships are writable?

+3
2

1) not-null dept_code , ( ?)

2) , setDepartment course_code setCourse , ?

+1

, , , ? , .

, SQL. < > , < sql-insert > , < sql-delete > < sq-update > . . https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html 13.3. .

CRUD: , , . . setDepartment getDepartment, DAO ( , ) .

Btw: JPA/Hibernate Manning ( " Java ", 8 - SQL).

+1

Source: https://habr.com/ru/post/1732802/


All Articles