2015-12-20 212 views
0

我只需要一個單向關係OneToMany,但是在性能方面我想問一下什麼是最佳實踐?在@OneToMany中使用Hibernate 4.2的性能 - 單向vs雙向

我沒有使用JUnit測試,並具有雙向結果是:1.9s和單向代碼2.4S,似乎單向需要更多的時間

我使用Hibernate的4.2.21

@Unidirectional 2.4S

Parent.class

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 
@JoinColumn(name = "parentuni_id") 
private Set<ChildUni> childs; 

Hibernate: select nextval ('parentuni_seq') 
Hibernate: select nextval ('childuni_seq') 
Hibernate: select nextval ('childuni_seq') 
Hibernate: insert into parentuni (parentuni_name, parentuni_id) values (?, ?) 
Hibernate: insert into childuni (childuni_name, childuni_id) values (?, ?) 
Hibernate: insert into childuni (childuni_name, childuni_id) values (?, ?) 
Hibernate: update childuni set parentuni_id=? where childuni_id=? 
Hibernate: update childuni set parentuni_id=? where childuni_id=? 

@Bidirectional 1.9s

Parent.class

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "parent") 
private Set<Child> childs; 

Child.class

@ManyToOne(fetch = FetchType.LAZY) 
@JoinColumn(name = "parent_id", nullable = false) 
private Parent parent; 

Hibernate: select nextval ('parent_seq') 
Hibernate: select nextval ('child_seq') 
Hibernate: select nextval ('child_seq') 
Hibernate: insert into parent (parent_name, parent_id) values (?, ?) 
Hibernate: insert into Child (child_name, parent_id, child_id) values (?, ?, ?) 
Hibernate: insert into Child (child_name, parent_id, child_id) values (?, ?, ?) 

回答

相關問題