Hibernate-20070516-1

Hibernate-20070516-1

Hibernate Quickstart

1、
Hibernate(2.1.7)
Hibernate-Extension
Middlegen-Hibernate
JUnit
MySql

2、
Copy MySql's driver and paste it in   /MiddleGen-Hibernate-r5/lib

3、Create Database "Sample" and table "t_user"(I use EMS SQL Manager to manager MySQL).

4.Create java POJO Tuser(hand write).

package  org.redsaga.quickstart;

import  java.io.Serializable;

public   class  Tuser  implements  Serializable  {
    
    
private Integer id;
    
private String name;
    
public Integer getId() {
        
return id;
    }

    
public void setId(Integer id) {
        
this.id = id;
    }

    
public String getName() {
        
return name;
    }

    
public void setName(String name) {
        
this.name = name;
    }

    

}

5.Use MiddleGen to create Tuser.hbm.xml
open mysql.xml(in  lib/MiddleGen-Hibernate-r5/config/database)  and set the properties

   
< property  name ="database.script.file"            value ="${src.dir}/sql/${name}-mysql.sql" />
   
< property  name ="database.driver.file"            value ="${lib.dir}/mysql-connector-java-3.2.0-alpha-bin.jar" />
   
< property  name ="database.driver.classpath"       value ="${database.driver.file}" />
   
< property  name ="database.driver"                 value ="org.gjt.mm.mysql.Driver" />
   
< property  name ="database.url"                    value ="jdbc:mysql://localhost/sample" />
   
< property  name ="database.userid"                 value ="root" />
   
< property  name ="database.password"               value ="root" />
   
< property  name ="database.schema"                 value ="" />
   
< property  name ="database.catalog"                value ="" />

   
< property  name ="jboss.datasource.mapping"        value ="mySQL" />


I have altered the database.driver.file ,database.url,database.userid and database.password  values.

6.Edit the build.xml of MiddleGen
(1)

<! DOCTYPE project [
    <!ENTITY database SYSTEM "file:./config/database/mysql.xml"
>
]>


(2)Application name

    < property  name ="name"  value ="HibernateSample" />

(3)Output Cataloge

    < property  name ="build.gen-src.dir"               value ="../../src" />

(4)Package name

< hibernate
            
destination ="${build.gen-src.dir}"
            package
="org.redsaga.quickstart"
            genXDocletTags
="false"
            genIntergratedCompositeKeys
="false"
            javaTypeMapper
="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
         
/>


Ok.Now,let's run build.xml.







errors:
1 java.lang.NoClassDefFoundError:org/dom4j/Attribute
  缺dom4j.jar

你可能感兴趣的:(Hibernate-20070516-1)