¿ìËÙÒµÎñͨµÀ

ϵͳѧϰhibernateÖ®Ò»£ºÀûÓÃhibernateÖеÄSchemaExportÉú³ÉÊý¾Ý - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-06-20

ϵͳѧϰhibernateÖ®Ò»£ºÀûÓÃhibernateÖеÄSchemaExportÉú³ÉÊý¾Ý

ʱ¼ä:2011-01-27 blogjava apple0668

ÓÉÓÚhibernate3ÌṩÁË×Ô´øµÄ¹¤¾ßhbm2ddl£¬½¨Á¢¸ù¾ÝÄãµÄ¶ÔÏó½¨Á¢Êý¾Ý¿âÊÇÒ»¼þ·Ç³£¼òµ¥µÄÊÂÇé¡£

Demo½á¹¹Í¼ÈçÏ£º

ϵͳѧϰhibernateÖ®Ò»£ºÀûÓÃhibernateÖеÄSchemaExportÉú³ÉÊý¾Ý - ±à³ÌÈëÃÅÍø

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

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!

·ÖÏíµ½£º ¸ü¶à

Copyright ©1999-2011 ÏÃÃÅÁèÖڿƼ¼ÓÐÏÞ¹«Ë¾ ÏÃÃÅÓÅͨ»¥Áª¿Æ¼¼¿ª·¢ÓÐÏÞ¹«Ë¾ All rights reserved

µØÖ·(ADD)£ºÏÃÃÅÈí¼þÔ°¶þÆÚÍûº£Â·63ºÅ701E£¨¶«ÄÏÈÚͨÅÔ£© Óʱà(ZIP)£º361008

µç»°£º0592-5908028 ´«Õ棺0592-5908039 ×ÉѯÐÅÏ䣺web@lingzhong.cn ×ÉѯOICQ£º173723134

¡¶ÖлªÈËÃñ¹²ºÍ¹úÔöÖµµçÐÅÒµÎñ¾­ÓªÐí¿ÉÖ¤¡·ÃöB2-20100024  ICP±¸°¸:ÃöICP±¸05037997ºÅ