'Hibernate - JoinColumn with harcoded value
I have the following entity :
@Entity
@Table(name = "REFERENCE_TABLE")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ReferenceEntity {
@Column(name = "TYPE_ID")
private String type;
@Id
@Column(name = "CODE")
private String code;
@Column(name = "LABEL")
private String label;
}
And the following entity
@Entity
@Table(name = "USER_TABLE")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserEntity {
@Id
@Column(name = "USER_ID")
private Long id;
@OneToOne
@Where(clause = "TYPE_ID = '503'")
@JoinColumn(name = "TITLE_CODE", referencedColumnName = "CODE")
private ReferenceEntity title;
}
But I get the following error : More than one row with the given identifier was found:.
The issue is because the where clause is ignored.
I need to join REFERENCE_TABLE.CODE = USER_TABLE.TITLE_CODE AND REFERENCE_TABLE.TYPE_ID = '503".
I tried to add @JoinColumn(name = "REFERENCE_TABLE.CODE", referencedColumnName = "'503'")
but it didn't work.
I also tried @JoinColumn(table = "REFERENCE_TABLE", name = "CODE", referencedColumnName = "'503'"), still not working.
How can I achieve that ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
