zoukankan      html  css  js  c++  java
  • hibernate4中主要的配置文件配置

    在hibernate中有两个主要的配置文件:hibernate.cfg.xml,xxx.hbm.xml。

    使用mysql数据库时,hibernate.cfg.xml配置文件如下:

    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>
        <session-factory >
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>        
             <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="connection.url">jdbc:mysql://localhost:3306/test_hibernate</property>
            <property name="connection.username">root</property>
            <property name="connection.password">123</property>
            
            <property name="show_sql">true</property>
            <property name="hbm2ddl.auto">update</property>
            
            <mapping resource="com/zc/hibernate/User.hbm.xml"/>
        </session-factory>
    </hibernate-configuration>

    User类代码如下:

    package com.zc.hibernate;

    import java.util.Date;

    public class User {

        private int id;
        private String username;
        private String password;
        private Date birthday;
        
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        public Date getBirthday() {
            return birthday;
        }
        public void setBirthday(Date birthday) {
            this.birthday = birthday;
        }
        
        
    }
    User类的映射文件:User.hbm.xml

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

    <hibernate-mapping  package="com.zc.hibernate">
        <class name="User" table="t_user">
         <id name="id">
                <generator class="native"/>
            </id>
        <property name="username"/>
        <property name="password"/>
        <property name="birthday" type="timestamp"/>
        </class>
    </hibernate-mapping>

  • 相关阅读:
    进程管理supervisor的简单说明
    flask扩展系列之
    爱奇艺面试Python,竟然挂在第5轮…(转)
    RabbitMQ最佳实践
    Linux生成私钥和公钥免密连接
    mongo 慢查询配置
    监控Mongo慢查询
    关于SIGSEGV错误及处理方法(转)
    深入理解JVM内幕(转)
    libpng使用
  • 原文地址:https://www.cnblogs.com/charleszhang1988/p/2936045.html
Copyright © 2011-2022 走看看