Hibernate3 Learning Notes (23) | Advanced characteristics (III.)

Source: Internet
Author: User

6. Generate a mapping file from a datasheet

You can automatically generate the mapping file from the table in the database, download Middlegen-hibernate first, and then unzip it after downloading.

The database used here is MySQL, and assume that the following tables are already in your database:

CREATE TABLE user (
   id INT(11) NOT NULL auto_increment PRIMARY KEY,
   name VARCHAR(100) NOT NULL default '',
   age INT
);

Into the Config/database directory after middlegen-hibernate decompression, open the Mysql.xml, modify the database configuration related information:

mysql.xml
<property name="database.script.file"
       value="${src.dir}/sql/${name}-mysql.sql"/>
  <property name="database.driver.file"
       value="${lib.dir}/mysql-connector-java-3.0.14-production-bin.jar"/>
  <property name="database.driver.classpath"
       value="${database.driver.file}"/>
  <property name="database.driver"
       value="com.mysql.jdbc.Driver"/>
  <property name="database.url"
       value="jdbc:mysql://localhost/demo"/>
  <property name="database.userid"
       value="caterpillar"/>
  <property name="database.password"
       value="123456"/>
  <property name="database.schema"
       value=""/>
  <property name="database.catalog"
       value=""/>
  <property name="jboss.datasource.mapping"
       value="mySQL"/>

Configure according to the environment

database.driver.file
database.driver.classpath
database.driver
database.url
database.userid
database.password

, the default JDBC driver for MySQL is placed under the Middlegen-hibernate Lib directory.

Middlegen-hibernate use ant constructs, you can refer to ant introduction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.