görkem balcısoy (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5bc87b3...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjM3OTM5ZDdl...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-14052?atlOrigin=eyJpIjoiMjM3OT...
) HHH-14052 (
https://hibernate.atlassian.net/browse/HHH-14052?atlOrigin=eyJpIjoiMjM3OT...
) @ManyToAny annotation transient instance error for Cascade.All (
https://hibernate.atlassian.net/browse/HHH-14052?atlOrigin=eyJpIjoiMjM3OT...
)
Issue Type: Bug Affects Versions: 5.4.15 Assignee: Unassigned Components: hibernate-core
Created: 31/May/2020 06:16 AM Priority: Major Reporter: görkem balcısoy (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5bc87b3...
)
I have below domain model. I added specialization entities both Product and ProductDetail
entities with @ManyToAny annotation. Also, Product entity has many ProductDetail
entities.
I want to save a new Product entity with one of its specializations and
productDetails(with one of its specializations,too).
I use merge() method for new Product saving process, but it produces an error:
org.hibernate.TransientObjectException: object references an unsaved transient instance -
save the transient instance before flushing:
com.test.model.FlyingProductDetailSpecialization.
I searched for this issue, but I cannot find anything that is different from
CascadeType.ALL usage answers. I used this cascade type.
If I use persist() method for new Product saving process, it results successful. But, if I
want to update this Product entity (with merge() method) with adding a productDetail with
its specializations, the same TransientObjectException also occurs.
Do you have any idea about this problem? Thanks.
(BaseObject class has createDate, updateDate, id columns. I don't add this class for
shortening the question.)
You can find this question at link:
https://stackoverflow.com/questions/62062582/manytoany-annotation-transie...
// Product Model
@Table(name="product")
@Entity
public class Product extends BaseObject
{ @OneToMany(mappedBy="product", cascade=CascadeType.ALL, orphanRemoval=true)
@LazyCollection(LazyCollectionOption.FALSE)
@JsonIgnoreProperties(value="product", allowSetters=true) private
List<ProductDetail> productDetails = new ArrayList<>();
@ManyToAny(metaDef="ProductSpecMetaDef",
metaColumn=@Column(name="product_specialization_type"))
@LazyCollection(LazyCollectionOption.FALSE)
@Cascade(org.hibernate.annotations.CascadeType.ALL) @JoinTable(
name="product_specialization_relationship",
joinColumns=@JoinColumn(name="product"),
inverseJoinColumns=@JoinColumn(name="product_specialization") ) private
List<ISpecialization<Product>> productSpecializations = new
ArrayList<>(); // and some string and numerical fields }
@Table(name="unused_product_specialization")
@Entity
public class UnusedProductSpecialization extends BaseObject implements
ISpecialization<Product>
{ // some string and numerical fields }
@Table(name="used_product_specialization")
@Entity
public class UsedProductSpecialization extends BaseObject implements
ISpecialization<Product>{ // some string and numerical fields }
// package-info definition for ManyToAny relationship
@AnyMetaDef(name="ProductSpecMetaDef", metaType="string",
idType="string",
metaValues=
{@MetaValue(value = "Unused", targetEntity=UnusedProductSpecialization.class),
@MetaValue(value = "Used", targetEntity=UsedProductSpecialization.class) }
)
// End of Product Model
// Product Detail Model
@Table(name="product_detail")
@Entity
public class ProductDetail extends BaseObject
{ @ManyToOne
@JoinColumn(name="product",referencedColumnName="id",nullable=false,
foreignKey=@ForeignKey(name="product_detail_product_fkey"))
@JsonIgnoreProperties(value="productDetails", allowSetters=true) private Product
product; @ManyToAny(metaDef="ProductDetailSpecMetaDef",
metaColumn=@Column(name="product_detail_specialization_type"))
@LazyCollection(LazyCollectionOption.FALSE)
@Cascade(org.hibernate.annotations.CascadeType.ALL) @JoinTable(
name="product_detail_specialization_relationship",
joinColumns=@JoinColumn(name="product_detail"),
inverseJoinColumns=@JoinColumn(name="product_detail_specialization") ) private
List<ISpecialization<ProductDetail>> productDetailSpecializations = new
ArrayList<>(); // and some string and numerical fields }
@Table(name="flying_product_detail_specialization")
@Entity
public class FlyingProductDetailSpecialization extends BaseObject implements
ISpecialization<ProductDetail>
{ // some string and numerical fields }
@Table(name="walking_product_detail_specialization")
@Entity
public class WalkingProductDetailSpecialization extends BaseObject implements
ISpecialization<ProductDetail>{ // some string and numerical fields }
// package-info definition for ManyToAny relationship
@AnyMetaDef(name="ProductDetailSpecMetaDef", metaType="string",
idType="string",
metaValues=
{@MetaValue(value = "Flying",
targetEntity=FlyingProductDetailSpecialization.class), @MetaValue(value =
"Walking", targetEntity=WalkingProductDetailSpecialization.class) }
)
// End of Product Detail Model
(
https://hibernate.atlassian.net/browse/HHH-14052#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-14052#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#100127- sha1:2c97aec )