Hello,
I am using hibernate(3.1) and Oracle DB version 10G and Springs in our application. I am experiencing an issue with Association. The Association we have implemented is kind of Parent(Batch)-> Child(Person) -> Grand Childs(PersonAttributes, PersonTracking). It is done using JPA. It is a one to Many relationship between batch and Person and again a onetoMany Person and PersonAttribute or Person and PersonTracking Attribute.
I am using sequences for key generation for batch, person, personAttributes and PersonTracking.
It works fine when I insert like 1(batch) having 2 Person which is having 2 PersonAttributes and 2 PersonTracking but when I increase it to say 10 batch, each having 10 person and each person having 10 personattributes and 5 persontracking records. The time taken to insert increases to something like 18 mins which is not acceptable.
While observing the association inserts we found that most of the time say 16 mins is taken by hibernate to populate the batch and its children with the sequence queries being fired repeatitively.
I also tried to look in documentation for a way where in we can enable a bulk insert for associations. I can do it only when insert is being made using a Single Java Object. However, in my case inserts is not taking that long time. It is the mapping of foreign key relationship and primary key population which is consuming the time.
Has any body faced a similar issue before? Please let me know if we have any suggestions on this to resolve.
Also giving the sample Formatted Code.
Appreciate your help and time.
Thanks
Navin
Code:
@Entity
@Table(name = "BATCH")
public class Batch {
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="BATCH_SEQ")
@SequenceGenerator(name="BATCH_SEQ", sequenceName="BATCH_SEQ" ,allocationSize=1 )
@Column(name = "BATCHID")
private Integer batchId;
.
.
@OneToMany( cascade=CascadeType.ALL, mappedBy="batch")
@org.hibernate.annotations.Cascade (value= org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@org.hibernate.annotations.OrderBy(clause="PROVISIONINGTXNNO asc")
private Set<Person> person=new HashSet<Person>(0);
..//other attributes
}
@Entity
@Table(name = "PERSON")
public class Person implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="PERSON_SEQ")
@SequenceGenerator(name="PERSON_SEQ", sequenceName="PERSON_SEQ" ,allocationSize=100)
@Column(name = "PROVISIONINGTXNNO")
private Integer id;
..
// Associations implemented
@OneToMany( cascade=CascadeType.ALL,mappedBy="person")
@org.hibernate.annotations.Cascade (value= org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<PersonAttribute> personAttribute = new HashSet<PersonAttribute>(0);
@OneToMany( cascade=CascadeType.ALL,mappedBy="personWork")
@org.hibernate.annotations.Cascade (value= org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<PersonTracking> personTracking = new HashSet<PersonTracking>(0);
..// other attributes
}
// Here is the insert piece.
DAOFactory daoFactory = DAOFactory.getFactoryInstance();
DAODataManager<Batch, Integer> dataManager = daoFactory.getDataManager("batch");
dataManager.insertItem(batches);