为了对hibernate有个了解,以后用到的时候不至于畏惧,决定先写个helloworld尝一尝。
首先是准备各种包
hibernate3.jar
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
mysql-connector-java-5.1.7-bin.jar//使用的是mysql数据库s
slf4j-nop-1.6.1.jar//注意slf4j-nop-1.6.1.jar和slf4j-api-1.6.1.jar需要版本相同,否则出现可能不兼容的情况。
slf4j-api-1.6.1.jar
下载地址
http://sourceforge.net/projects/hibernate/files/hibernate3/
http://www.slf4j.org/download.html
http://dev.mysql.com/downloads/
/********************开始*************************/
1.数据库
使用mysql数据库,名称hibernate_helloworld,
表名customers(id int primary key,name char(10)not null,password char(10) not null);
2.在myeclipse中新建项目如:hibernate_helloworld
3.hibernate的配置文件
1).hibernate.cfg.xml(名字可以改变xxx.cfg.xml,不过好像还有些复杂的)
放在src目录下(也可以放在其他目录下,这样需要在classpath里设置)
2).Customer.hbm.xml 该文件的位置具体和hibernate.cfg.xml中的mapping一致即可
4.与表Customer对应的JavaBean
5.到这里,Hibernate的配置完成了,接下来是测试代码