'Join two JPA bidirectionally having same col names?
I've two table
@Entity
@NamedEntityGraph(name = "one", attributeNodes = {@NamedAttributeNode("two")})
@Table(name = "one")
One.class {
@Id
private sno;
private String version;
@Column(name = "bgn_no")
private String bgnNo;
@OnetoOne(cascade = CascadeType.All, fetch = FetchType.EAGER)
@JoinColumn(name = "bgn_no", referenceColumnName = "bgn_no", insertable = false, updatable = false)
private Two two;
}
@Entity
@Table(name = "two")
Two.class {
@Id
private dim_no;
@Column(name = "bgn_no")
private String bgnNo;
private location;
private region;
@OneToOne(mappedBy = "two") -> issue
private One one; -> issue
}
repository
BGNRepository extends PagingAndSortingRepository<One, String> {
@EntityGraph(value = "one")
One finfbyBgnNo(String no);
}
calling above repository using servcieBGNRepository.finfbyBgnNo(String no, String ver)
There are some other columns too in entities, but am joining on the basis bgn_no col. This col is present in both tables with same names. Above repository works fine only when -> issue lines are removed from above code, else giving below error
Getting error
Error Accessing field (private Two.bgn_no] by reflection for persistent property [Two#bgn_no], nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private Two.bgn_no ] by reflectionfor persistent property[ Two#bgn_no]
I'm literally stuck on this issue. Can anyone suggest what can be done. I've tried adding getter/setter too. But still same issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
