Gaurang Parmar (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=635c2c2...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjYyY2RlNDRk...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15643?atlOrigin=eyJpIjoiNjYyY2...
) HHH-15643 (
https://hibernate.atlassian.net/browse/HHH-15643?atlOrigin=eyJpIjoiNjYyY2...
) @OneToOne bidirectional relation ignores @JoinColumn referencedColumnName (
https://hibernate.atlassian.net/browse/HHH-15643?atlOrigin=eyJpIjoiNjYyY2...
)
Issue Type: Bug Affects Versions: 5.6.12 Assignee: Unassigned Attachments: onetoone.log
Components: hibernate-orm-modules Created: 28/Oct/2022 12:50 PM Priority: Major Reporter:
Gaurang Parmar (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=635c2c2...
)
I am trying to add one-to-one bidirectional relationship on non-primary key unique key
field.
full code is available at
https://github.com/gaurangparmar/jpa (
https://github.com/gaurangparmar/jpa )
OrderHeader.java
@Entity
@Table(name = "ORD_HDR" ,schema="ORDERS", uniqueConstraints = {
@UniqueConstraint(name = "ORD_HDR_UK1", columnNames = { "ORD_ID" })})
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=false)
public class OrderHeader implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ORD_HDR_ID", nullable = false, updatable = false)
@SequenceGenerator( name = "ORD_HDR_ID_SEQ", sequenceName =
"ORDERS.ORD_HDR_ID_SEQ", allocationSize = 1, initialValue = 1)
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator =
"ORD_HDR_ID_SEQ" )
private int orderHeaderId;
@Column(name = "ORD_ID", nullable = false, updatable = false, length = 10)
private String orderId;
.....
@Column(name="DLV_DT")
private LocalDate deliveryDate;
@OneToOne(mappedBy = "orderHeader", fetch = FetchType.LAZY, cascade =
CascadeType.ALL,orphanRemoval = false)
private OrderMeta orderMeta;
}
OrderMeta.java
@Entity
@Table(name = "ORD_META" ,schema="ORDERS", uniqueConstraints = {
@UniqueConstraint(name = "ORD_META_UK1", columnNames = { "ORD_ID"
})})
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper=false)
public class OrderMeta implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ORD_META_ID", nullable = false, updatable = false)
@SequenceGenerator( name = "ORD_META_ID_SEQ", sequenceName =
"ORDERS.ORD_META_ID_SEQ", allocationSize = 1, initialValue = 1)
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator =
"ORD_META_ID_SEQ" )
private int orderMetaId;
@Column(name = "ORD_ID", nullable = false, updatable = false, length = 10)
private String orderId;
......
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL,orphanRemoval = false)
@JoinColumn(name="ORD_ID", referencedColumnName = "ORD_ID",
nullable = false, insertable = false, updatable = false)
private OrderHeader orderHeader;
}
orderId in both tables are unique and Primary/Main entity is OrderHeader and OrderMeta is
having foreign key orderId referencing to OrderHeader.
Full logs are attached from test case run. I believe it is trying to fetch related entity
data by primary key and ignoring specified joincolumn.
Error accessing field [private java.lang.String
com.gaurang.test.entity.OrderHeader.orderId] by reflection for persistent property
[com.gaurang.test.entity.OrderHeader#orderId] : 1; nested exception is
org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private
java.lang.String com.gaurang.test.entity.OrderHeader.orderId] by reflection for persistent
property [com.gaurang.test.entity.OrderHeader#orderId] : 1
org.springframework.orm.jpa.JpaSystemException: Error accessing field [private
java.lang.String com.gaurang.test.entity.OrderHeader.orderId] by reflection for persistent
property [com.gaurang.test.entity.OrderHeader#orderId] : 1; nested exception is
org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private
java.lang.String com.gaurang.test.entity.OrderHeader.orderId] by reflection for persistent
property [com.gaurang.test.entity.OrderHeader#orderId] : 1
...
...
Caused by: org.hibernate.property.access.spi.PropertyAccessException: Error accessing
field [private java.lang.String com.gaurang.test.entity.OrderHeader.orderId] by reflection
for persistent property [com.gaurang.test.entity.OrderHeader#orderId] : 1
at app//org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:75)
...
...
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field
com.gaurang.test.entity.OrderHeader.orderId to java.lang.Integer
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at
java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.base/java.lang.reflect.Field.get(Field.java:425)
at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:71)
... 136 more
I understand one-to-one relation better have primary key as foreign key but it is really
dumb key for business and ETL uses this dumb keys. we really needed this to work.
(
https://hibernate.atlassian.net/browse/HHH-15643#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15643#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100209- sha1:d23b292 )