时间:2021-07-01 10:21:17 帮助过:35人阅读
最近在深入学习hibernate,在进行批量操作时,发现hibernate批量操作性能非常低.于是就想找一个性能较高的方法,在对jdbc、jdbcTemplate、hibernate进行测试后,发现jdbc的执行效率是最高的,jdbcTemplate也很相近,hibernate就不考虑了,惨不忍睹啊.下面把代码写出来,希望大家批评指正.
首先domain对象.在这里使用的注解的方式,都是比较新的版本.
User.java1 package com.bao.sample.s3h4.domain; 2 3 import javax.persistence.Column; 4 import javax.persistence.Entity; 5 import javax.persistence.GeneratedValue; 6 import javax.persistence.GenerationType; 7 import javax.persistence.Id; 8 import javax.persistence.Table; 9 10 import com.bao.sample.base.domain.BaseDomain;11 12 @Entity13 @Table(name = "t_user")14 public class User extends BaseDomain {15 16 private static final long serialVersionUID = 1L;17 private int id;18 private String username;19 private String password;20 21 /**22 * @Description 注解最好标记在get方法上.注意:采用一致的标记方式,注解是以Id的标记方式为准的,如果标记在get方法上,则忽略property上的注解.23 * @return24 */25 @Id26 @GeneratedValue(strategy = GenerationType.IDENTITY)27 public int getId() {28 return id;29 }30 31 public void setId(int id) {32 this.id = id;33 }34 35 @Column(nullable = false)36 public String getUsername() {37 return username;38 }39 40 public void setUsername(String username) {41 this.username = username;42 }43 44 @Column(nullable = false)45 public String getPassword() {46 return password;47 }48 49 public void setPassword(String password) {50 this.password = password;51 }52 53 public User() {54 super();55 }56 57 public User(int id, String username, String password) {58 super();59 this.id = id;60 this.username = username;61 this.password = password;62 }63 64 }bitsCN.com