Spring Data JDBC — отношение «многие к одному» ⇐ JAVA
-
Гость
Spring Data JDBC — отношение «многие к одному»
I can't seem to find any reference online with regards to using a Many-To-One mapping in Spring JDBC. I just saw in the documentation that is not supported but I'm not sure if this is the case.
My example is that I want to map my AppUser to a particular Department.
For reference, AppUser joins to Department table using DEPARTMENT_ID
@Table(value="m_appuser") public class AppUserProjectionTwo { @Id private Long id; private String firstname; private String middlename; private String lastname; @Column("DEPARTMENT_ID") private DepartmentProjection departmenProjection; public Long getId() { return id; } public void setId(Long id) { this.id = id; } However, it seems that it won't map properly.
@Table("M_DEPARTMENT") public class DepartmentProjection { @Id private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } The created query looks like this. I was looking for something more of the opposite in which M_APPUSER.department_ID = Department.id
[SELECT "m_appuser"."ID" AS "ID", "m_appuser"."LASTNAME" AS "LASTNAME", "m_appuser"."FIRSTNAME" AS "FIRSTNAME", "m_appuser"."MIDDLENAME" AS "MIDDLENAME", "departmenProjection"."ID" AS "DEPARTMENPROJECTION_ID" FROM "m_appuser" LEFT OUTER JOIN "M_DEPARTMENT" AS "departmenProjection" ON "departmenProjection"."DEPARTMENT_ID" = "m_appuser"."ID" WHERE "m_appuser"."FIRSTNAME" = ?]; Thanks
Источник: https://stackoverflow.com/questions/648 ... lationship
I can't seem to find any reference online with regards to using a Many-To-One mapping in Spring JDBC. I just saw in the documentation that is not supported but I'm not sure if this is the case.
My example is that I want to map my AppUser to a particular Department.
For reference, AppUser joins to Department table using DEPARTMENT_ID
@Table(value="m_appuser") public class AppUserProjectionTwo { @Id private Long id; private String firstname; private String middlename; private String lastname; @Column("DEPARTMENT_ID") private DepartmentProjection departmenProjection; public Long getId() { return id; } public void setId(Long id) { this.id = id; } However, it seems that it won't map properly.
@Table("M_DEPARTMENT") public class DepartmentProjection { @Id private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } The created query looks like this. I was looking for something more of the opposite in which M_APPUSER.department_ID = Department.id
[SELECT "m_appuser"."ID" AS "ID", "m_appuser"."LASTNAME" AS "LASTNAME", "m_appuser"."FIRSTNAME" AS "FIRSTNAME", "m_appuser"."MIDDLENAME" AS "MIDDLENAME", "departmenProjection"."ID" AS "DEPARTMENPROJECTION_ID" FROM "m_appuser" LEFT OUTER JOIN "M_DEPARTMENT" AS "departmenProjection" ON "departmenProjection"."DEPARTMENT_ID" = "m_appuser"."ID" WHERE "m_appuser"."FIRSTNAME" = ?]; Thanks
Источник: https://stackoverflow.com/questions/648 ... lationship