Hi,
I have previously mapped two separate properties within one class to the same column, and just need to set "insertable = false, updatable = false" on one of those properties that is read only.
I now have a class called Script that inherits from class Item of which I want a property that uses the column from the parent class (and table) that is already mapped in the parent class.
Code:
@Entity()
@Table(name = "Item")
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int itemId;
@ManyToOne(fetch = FetchType.LAZY, optional = true, targetEntity = Item.class)
@JoinColumn(referencedColumnName = "itemId")
private Item parent;
}
@Entity()
@Table(name = "Script")
@Inheritance(strategy = InheritanceType.JOINED)
public class Script extends Item{
@ManyToOne(fetch = FetchType.LAZY, optional = true, targetEntity = Packet.class)
@JoinColumn(name = "parent_itemid", insertable = false, updatable = false)
private Packet packet;
}
Here I need Script.packet to be mapped to the same column as parent in the Item class (so parent_itemid in the Item table).
Any ideas if this is possible and how I would manage to code this?
At the moment it fails because the SQL generated expects parent_itemid to be on the Script table.
Any help would be appreciated.