Hi, I'm new to annotations & using Hibernate outside of Spring. I'm not sure what my configuration needs to be in order to do this (or if you can)
I'm retrieveing a child entity directly from Hibernate with a query including it's parent entity with cross-references. The child entity is the only object in a collection which could have another (1000?) rows in the db with same foreign key value.
I process some logic to create 2 or more instances of the child class and distribute some numeric values between them. The I want the original row deleted and the new entities persisted.
it seems that as soon as I hit the first add, that the entire collection is fetched. Is there a way to supress this and still have it work correctly? There is an obvious overhead in create 1000+ objects that are not needed.
Here are my mappings:
Parent:
@OneToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.LAZY, mappedBy = "payrollHeader")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<PayrollDetail> payrollDetails = new HashSet<PayrollDetail>();
...
Child:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="PayrollHeaderID", nullable=false)
public PayrollHeader getPayrollHeader() {
return this.payrollHeader;
}
Thanks for any insight.
I'm retrieveing a child entity directly from Hibernate with a query including it's parent entity with cross-references. The child entity is the only object in a collection which could have another (1000?) rows in the db with same foreign key value.
I process some logic to create 2 or more instances of the child class and distribute some numeric values between them. The I want the original row deleted and the new entities persisted.
it seems that as soon as I hit the first add, that the entire collection is fetched. Is there a way to supress this and still have it work correctly? There is an obvious overhead in create 1000+ objects that are not needed.
Here are my mappings:
Parent:
@OneToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.LAZY, mappedBy = "payrollHeader")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private Set<PayrollDetail> payrollDetails = new HashSet<PayrollDetail>();
...
Child:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="PayrollHeaderID", nullable=false)
public PayrollHeader getPayrollHeader() {
return this.payrollHeader;
}
Thanks for any insight.