idea hibernate jpa 生成实体类的实现
本篇博客记录下IDEA中连接数据库反转生成Hibernate实体和配置文件。
1.打开DataBase窗口,添加数据源
然后选择数据源,选择包,添加生成Bean的后缀,选择表,选择生成xml配置文件还是注解。
OK,结束
如果你选择生成带JPA注解类,映射文件是可以省略的,相反如果你生成映射文件,JPA注解也可以省略。
看你喜欢哪种方式
生成注解例子
@Entity @Table(name="user",schema="db_test",catalog="") publicclassUserPO{ privateStringuuid; privateStringname; privateStringpasswd; privateStringsex; privateTimestampbirthday; privateStringphone; privateStringphoto; privateStringemail; privateStringyxbz; privateStringsorts; @Id @Column(name="UUID") publicStringgetUuid(){ returnuuid; } publicvoidsetUuid(Stringuuid){ this.uuid=uuid; } @Basic @Column(name="NAME") publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } @Basic @Column(name="PASSWD") publicStringgetPasswd(){ returnpasswd; } publicvoidsetPasswd(Stringpasswd){ this.passwd=passwd; } @Basic @Column(name="SEX") publicStringgetSex(){ returnsex; } publicvoidsetSex(Stringsex){ this.sex=sex; } @Basic @Column(name="BIRTHDAY") publicTimestampgetBirthday(){ returnbirthday; } publicvoidsetBirthday(Timestampbirthday){ this.birthday=birthday; } @Basic @Column(name="PHONE") publicStringgetPhone(){ returnphone; } publicvoidsetPhone(Stringphone){ this.phone=phone; } @Basic @Column(name="PHOTO") publicStringgetPhoto(){ returnphoto; } publicvoidsetPhoto(Stringphoto){ this.photo=photo; } @Basic @Column(name="EMAIL") publicStringgetEmail(){ returnemail; } publicvoidsetEmail(Stringemail){ this.email=email; } @Basic @Column(name="YXBZ") publicStringgetYxbz(){ returnyxbz; } publicvoidsetYxbz(Stringyxbz){ this.yxbz=yxbz; } @Basic @Column(name="SORTS") publicStringgetSorts(){ returnsorts; } publicvoidsetSorts(Stringsorts){ this.sorts=sorts; } @Override publicbooleanequals(Objecto){ if(this==o)returntrue; if(o==null||getClass()!=o.getClass())returnfalse; UserPOuserPO=(UserPO)o; if(uuid!=null?!uuid.equals(userPO.uuid):userPO.uuid!=null)returnfalse; if(name!=null?!name.equals(userPO.name):userPO.name!=null)returnfalse; if(passwd!=null?!passwd.equals(userPO.passwd):userPO.passwd!=null)returnfalse; if(sex!=null?!sex.equals(userPO.sex):userPO.sex!=null)returnfalse; if(birthday!=null?!birthday.equals(userPO.birthday):userPO.birthday!=null)returnfalse; if(phone!=null?!phone.equals(userPO.phone):userPO.phone!=null)returnfalse; if(photo!=null?!photo.equals(userPO.photo):userPO.photo!=null)returnfalse; if(email!=null?!email.equals(userPO.email):userPO.email!=null)returnfalse; if(yxbz!=null?!yxbz.equals(userPO.yxbz):userPO.yxbz!=null)returnfalse; if(sorts!=null?!sorts.equals(userPO.sorts):userPO.sorts!=null)returnfalse; returntrue; } @Override publicinthashCode(){ intresult=uuid!=null?uuid.hashCode():0; result=31*result+(name!=null?name.hashCode():0); result=31*result+(passwd!=null?passwd.hashCode():0); result=31*result+(sex!=null?sex.hashCode():0); result=31*result+(birthday!=null?birthday.hashCode():0); result=31*result+(phone!=null?phone.hashCode():0); result=31*result+(photo!=null?photo.hashCode():0); result=31*result+(email!=null?email.hashCode():0); result=31*result+(yxbz!=null?yxbz.hashCode():0); result=31*result+(sorts!=null?sorts.hashCode():0); returnresult; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。