ϵͳѧϰhibernateÖ®Ò»£ºÀûÓÃhibernateÖеÄSchemaExportÉú³ÉÊý¾Ý
ʱ¼ä:2011-01-27 blogjava apple0668
ÓÉÓÚhibernate3ÌṩÁË×Ô´øµÄ¹¤¾ßhbm2ddl£¬½¨Á¢¸ù¾ÝÄãµÄ¶ÔÏó½¨Á¢Êý¾Ý¿âÊÇÒ»¼þ·Ç³£¼òµ¥µÄÊÂÇé¡£
Demo½á¹¹Í¼ÈçÏ£º
1¡¢Ê×ÏȽ¨Á¢POJOÀà
1package org.apple.hibernate;
2
3public class User {
4¡¡¡¡private String id;
5¡¡¡¡private String name;
6¡¡¡¡private String password;
7¡¡¡¡public String getId() {
8¡¡¡¡¡¡¡¡return id;
9¡¡¡¡}
10¡¡¡¡public void setId(String id) {
11¡¡¡¡¡¡¡¡this.id = id;
12¡¡¡¡}
13¡¡¡¡public String getName() {
14¡¡¡¡¡¡¡¡return name;
15¡¡¡¡}
16¡¡¡¡public void setName(String name) {
17¡¡¡¡¡¡¡¡this.name = name;
18¡¡¡¡}
19¡¡¡¡public String getPassword() {
20¡¡¡¡¡¡¡¡return password;
21¡¡¡¡}
22¡¡¡¡public void setPassword(String password) {
23¡¡¡¡¡¡¡¡this.password = password;
24¡¡¡¡}
25
26}
2¡¢¸ù¾ÝPOJOÀàÀïÃæÀïÃæÏà¹ØµÄ×Ö¶ÎдUser.hbm.xmlÓ³ÉäÎļþ
1<?xml version="1.0" encoding="GB2312"?>
2<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
3<hibernate-mapping>
4¡¡¡¡<class name="org.apple.hibernate.User">
5¡¡¡¡¡¡¡¡<!--hibernateΪÎÒÃÇÉú³ÉÖ÷¼üid-->
6¡¡¡¡¡¡¡¡<id name = "id" unsaved-value = "null">
7¡¡¡¡¡¡¡¡¡¡¡¡<generator class="uuid.hex"/>
8¡¡¡¡¡¡¡¡</id>
9
10¡¡¡¡¡¡¡¡<!--ĬÈÏ°ÑÀàµÄ±äÁ¿Ó³ÉäΪÏàͬÃû×ֵıíÁУ¬µ±È»ÎÒÃÇ¿ÉÒÔÐÞ¸ÄÆäÓ³É䷽ʽ-->
11¡¡¡¡¡¡¡¡<property name="name"/>
12¡¡¡¡¡¡¡¡<property name="password"/>
13¡¡¡¡</class>
14</hibernate-mapping>
ϵͳѧϰhibernateÖ®Ò»£ºÀûÓÃhibernateÖеÄSchemaExportÉú³ÉÊý¾Ý(2)
ʱ¼ä:2011-01-27 blogjava apple0668
3¡¢½¨Á¢hibernate.cfg.xml
1<!DOCTYPE hibernate-configuration PUBLIC
2¡¡¡¡"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
3¡¡¡¡"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
4
5<hibernate-configuration>
6¡¡¡¡<session-factory>
7
8¡¡¡¡¡¡¡¡<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
9¡¡¡¡¡¡¡¡<property name="hibernate.show_sql">true</property>
10¡¡¡¡¡¡¡¡<mapping resource="org/apple/hibernate/Person.hbm.xml"/>
11¡¡¡¡</session-factory>
12</hibernate-configuration>
4¡¢½¨Á¢ hibernate.propertiesÊý¾Ý¿âÁ´½Ó
## Êý¾Ý¿âÁ´½Ó£¬ÃÜÂë×Ô¼º¸ù¾Ý×Ô¼ºµÄʵ¼ÊÊý¾Ý¿â½øÐÐÐ޸ģ¡
hibernate.dialect org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/usertest?useUnicode=true&characterEncoding=GBK
hibernate.connection.username root
hibernate.connection.password password
5¡¢½¨Á¢UserTestÀà
1package org.apple.hibernate;
2
3import org.hibernate.cfg.Configuration;
4import org.hibernate.tool.hbm2ddl.SchemaExport;
5
6
7
8class UserTest{
9¡¡¡¡public static void main(String[] args) throws Exception{
10¡¡¡¡¡¡¡¡//ÅäÖû·¾³£¬·ÖÎöxmlÓ³ÉäÎļþ
11¡¡¡¡¡¡¡¡Configuration conf= new Configuratio
|