Is there any possible variant to insert data from another table into Hibernate entity. For example we have the following DB-model:
ItemTable:
ITEM_ID NUMBER not null,
ITEM_NAME VARCHAR2,
I_OBJECT_ID NUMBER;
ObjectTable:
OBJECT_ID NUMBER not null,
OBJECT_NAME VARCHAR2;
And the following java-code:
@Entity
@Getter
@Setter
@Table(name = "ITEMTABLE")
public class ItemDTO {
@Id
@Column(name = "ITEM_ID")
private long id;
@Column(name = "ITEM_NAME")
private String itemName;
@Column(name = "I_OBJECT_ID")
protected long objectId;
**//TODO: here we need OBJECT_NAME column form ObjectTable**
private String objectName;
}
So we need just one column not the whole ObjectTable entity for objectName prop.
I've tried construction like:
@JoinTable(name = "OBJECTTABLE", joinColumns = {
@JoinColumn(name = "OBJECT_ID", referencedColumnName = "I_OBJECT_ID") })
@Column(name = "OBJECT_NAME")
But it fails with:
oracle.jdbc.OracleDatabaseException: ORA-00904: "ITEMDTO0_"."OBJECT_NAME": invalid identifier
Every example of @JoinTable or @JoinColumn assume that I need to include another entity as a prop which will be redundant and slow.
Can this be solved in any way?
P.S. just two cents about why I do not want include second entity into first one, is because I want my JpaRepository will allow me to sort/filter directly over joined column.
Please advise.