Reputation: 157
I am trying to insert or update few records in oracle using hibernate. I am having around 2000 entities (records), which i am currently inserting/updating one by one sequentially. this is taking a lot of time for me to complete as hibernate internally selecting and then doing insert/update. I want to know is there a way that i can do bulk insert/update in hibernate. If yes, please do let me know how i can do that. and also do let me know are there any bottlenecks in doing bulk operations. below is the way how i am doing save/update using hibernate
@Autowired
private SessionFactory session;
private Session getSession() {
return session.getCurrentSession();
}
@Override
public Integer saveOrUpdateTest(Test test) {
getSession().saveOrUpdate(test);
return test.getTestId();
}
Below is the entity class that i am using.
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="Test")
public class Test implements Serializable{
private static final long serialVersionUID = 8844487972789619819L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="TEST_ID")
private Integer testid;
@Column(name="EMPLOYEE_ID")
private Integer employee_ID;
@Column(name="EMPLOYEE_SUB_ID")
private Integer employee_Sub_ID;
public Integer getTestId() {
return testid;
}
public void setTestId(Integer testid) {
this.testid = testid;
}
public Integer getEmployeeId() {
return employee_ID;
}
public void setEmployeeId(Integer employee_ID) {
this.employee_ID = employee_ID;
}
public Integer getEmployeeSubId() {
return employee_Sub_ID;
}
public void setCapEmployeeSubId(Integer employee_Sub_ID) {
this.employee_Sub_ID = employee_Sub_ID;
}
}
Upvotes: 1
Views: 595