最近在学习java EE的一个持久层框架 Hibernate,刚写了一个入门级的案例,赶忙记录下来java
话很少说,上项目.....mysql
项目的结构 sql
接下来是 hibernate.cfg.cml ,能够说是核心配置文件了数据库
<!-- lang: java --> <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/test</property> <property name="connection.username">root</property> <property name="connection.password">root@wangming</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">none</property> <mapping resource="com/wm/model/Account.cfg.xml"/> </session-factory> </hibernate-configuration>
next.....session
Account.javaapp
<!-- lang: java --> package com.wm.model; public class Account { private Integer id; private String firstname; private String lastname; private String emailAddress; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } }
Account.cfg.xml文件框架
<!-- lang: java --> <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.wm.model"> <class name="Account" table="account"> <id name="id" column="id"> <generator class="increment"/> </id> <property name="firstname" /> <property name="lastname" /> <property name="emailAddress" /> </class> </hibernate-mapping>
这里的Account对应的是数据库的一张表 里面的字段学习
id int firstname String lastname String emailAddress String`
建好这张表,接下来就能够测试了测试
固然,由于时间缘由,配置都很基础,可是运行仍是没有问题的,能够做为查看hibernate效果的 一个小的测试吧,接下来我会继续深刻下去ui