惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 方寸心间

改进的前序遍历树模型(The Nested Set Model) Strtus2 Convention Plugin - 方寸心间 【转】Java数组排序总结(冒泡,选择,插入,希尔) 【转】关于Hibernate的unsaved-value 【转】IntelliJ IDEA使用技巧一览表 【转】maven2完全使用手册 【转】HSQLDB安装与使用 【转】response.setHeader参数、用法的介绍 - 方寸心间 - 博客园 Spring中使用proxool的配置+【转】proxool.xml配置属性说明 [Ubuntu][MySQL]修改MySQL编码 [Ubuntu]下安装subversion Linux下./configure错误详解 【转】CVS使用手册 [MySQL]用户密码管理 [MySQL]MySql-front连接LINUX平台的MySQL服务 - 方寸心间 [Ubuntu]Apt-get命令参数详解 - 方寸心间 sun jdk,Tomcat在Linux下的安装 - 方寸心间 [Gentoo]中文输入软件Scim的安装【转】 - 方寸心间 [Gentoo]系统时间调整【转】
hibernate3.2由hbm文件生成pojo和ddl
方寸心间 · 2008-12-12 · via 博客园 - 方寸心间

准备:
1.apache-ant-1.7.0.
2.hibernate-3.2.1.ga.zip,HibernateTools-3.2.1.ga.zip.
3.数据库的jdbc驱动程序,我使用的是mysql,驱动程序为mysql-connector-java-5.1.6。

项目布置:
1.建立Project-Name文件夹,其下建立:config,java,schema,lib文件夹以及build.xml文件.
2.加入jar包:hibernate3.jar,hibernate-tools.jar,freemarker.jar,mysql-connector-java.jar,...
3.src/hibernate.cfg.xml:

<?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>
  
<property name="connection.username">root</property>
  
<property name="connection.password">cosmo</property><!--Your DB password here.-->
  
<property name="connection.url">jdbc:mysql://localhost:3306/MasteryHibernate</property>
  
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  
<mapping resource="chapter3/Customer.hbm.xml" />
 
</session-factory>
</hibernate-configuration>

4.src/your-package/Customer.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
><hibernate-mapping>
    
<class name="chapter3.Customer" table="CUSTOMERS">
        
<meta attribute="class-description">
            Represents a single customer.
            @author Cosmo
        
</meta><meta attribute="class-scope">public</meta><id name="id" type="long" column="ID">
            
<meta attribute="scope-set">protected</meta>
            
<generator class="native" />
        
</id><property name="name" type="string">
            
<meta attribute="use-in-tostring">true</meta>
            
<column name="NAME" length="15" not-null="true" unique="true" />
        
</property><property name="registeredTime" type="timestamp">
            
<meta attribute="field-description">When the customer was registered</meta>
            
<meta attribute="use-in-tostring">true</meta>
            
<column name="REGISTERED_TIME" index="IDX_REGISTERED_TIME"
                sql-type
="timestamp" />
        
</property>
        
        
<property name="age" type="int">
            
<meta attribute="field-description">How old is the customer</meta>
            
<meta attribute="use-in-tostring">true</meta>
            
<column name="AGE" check="AGE>10" not-null="true" />
        
</property>
        
        
<property name="sex" type="char" column="SEX" />
        
        
<property name="married" type="boolean" column="IS_MARRIED">
            
<meta attribute="field-description">Is the customer married</meta>
            
<meta attribute="use-in-tostring">true</meta>
        
</property>
        
        
<property name="description" type="string">
            
<meta attribute="use-in-tostring">true</meta>
            
<column name="DESCRIPTION" sql-type="text" />
        
</property>
    
</class>
</hibernate-mapping>

5.build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== 
     2008-12-12 下午02:47:47                                                        

     Hbm2javaAndHbm2ddl    
     Useing hibernate-tools
                   
     Cosmo                                                                
     ====================================================================== 

-->
<project name="AboutHibernateTools" default="compile">
    
<description>
            AboutHibernateTools
    
</description><property name="source.root" value="./src" />
    
<property name="class.root" value="./classes" />
    
<property name="lib.dir" value="./lib" />
    
<property name="schema.dir" value="./schema" /><path id="project.class.path">
        
<pathelement location="${class.root}" />
        
<fileset dir="${lib.dir}">
            
<include name="*.jar" />
        
</fileset>
    
</path><!-- ================================= 
          target: run              
         ================================= 
-->
    
<target name="run" depends="hbm2ddl" description="Run a Hibernate sample">
        
<java classname="chapter3.BusinessService" fork="true">
            
<classpath refid="project.class.path" />
        
</java>
    
</target><!-- ================================= 
          target: hbm2ddl              
         ================================= 
-->
    
<target name="hbm2ddl" depends="compile" description="Generate DB schema from the O/R mapping files">
        
<mkdir dir="${schema.dir}" />
        
<taskdef name="hbm2ddl" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path" />
        
<hbm2ddl destdir="${schema.dir}">
            
<configuration configurationfile="${class.root}/hibernate.cfg.xml" />
            
<hbm2ddl export="true" console="false" create="true" update="false" drop="false" outputfilename="schema.sql" />
        
</hbm2ddl>
    
</target><!-- ================================= 
          target: compile              
         ================================= 
-->
    
<target name="compile" depends="hbm2java" description="Chapter3">
        
<javac srcdir="${source.root}" destdir="${class.root}" debug="on" optimize="off" deprecation="on">
            
<classpath refid="project.class.path" />
        
</javac>
    
</target><!-- ================================= 
          target: hbm2java              
         ================================= 
-->
    
<target name="hbm2java" depends="prepare" description="Generate Java source from the O/R mapping files">
        
<taskdef name="hbm2java" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path" />
        
<hbm2java destdir="${source.root}">
            
<configuration configurationfile="${class.root}/hibernate.cfg.xml" />
            
<hbm2java jdk5="true" />
        
</hbm2java>
    
</target><!-- - - - - - - - - - - - - - - - - - 
          target: prepare                      
         - - - - - - - - - - - - - - - - - 
-->
    
<target name="prepare">
        
<delete dir="${class.root}" />
        
<mkdir dir="${class.root}" /><copy todir="${class.root}">
            
<fileset dir="${source.root}">
                
<include name="**/*.properties" />
                
<include name="**/*.hbm.xml" />
                
<include name="**/*.cfg.xml" />
            
</fileset>
        
</copy>
    
</target></project>