Hi Paul,
I think you are misusing the JOINED feature. When you map a hierarchy
using JOINED you are simply telling JPA that it should persist
additional fields in different tables. This does not mean that they are
separate entities or that it's possible to transform one entity to
another class. Even if JPA is saving on more than one table, that is a
single and unique entity, and cannot be considered like two different
entities (a parent and a child one), so persist or delete one and not
the other.
The only way I can think of is creating a new UserProduct entity,
transfer data from the MyProduct instance to the new one, delete the
MyProduct instance, then persist the new one preserving the id, but this
could cause a number of problems if other bean are referencing this
entity assuming it is a MyProduct.
Probably, if you need to use MyProduct and UserProduct as separate
entity, you should not have one extend the other, but have two distinct
entities connected one to the other using a @OneToOne. For example :
public class UserProduct {
@OneToOne
private MyOptionalData mydata;
}
public class MyOptionalData {
@OneToOne
private UserProduct product;
}
Hope it helps,
Simone
[email protected] wrote:
I have a class defined as
@Entity
@Table(name = "user_product")
@Inheritance(strategy = InheritanceType.JOINED)
public class UserProduct implements Serializable {
private Integer productid;
}
then I have a child class defined as
@Entity
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "productid")
public class MyProduct extends UserProduct implements Serializable {
private Integer id;
}
How do I delete MyProduct without deleting its parent? The parent
needs to be just updated, but not deleted.
When I try to set a value and merge UserProduct, and then delete
MyProduct I get "An optimistic lock violation was detected when
flushing object instance...".
Help is very much appreciated.
--
Simone Gianni CEO Semeru s.r.l. Apache Committer
http://www.simonegianni.it/