码迷,mamicode.com
首页 > 其他好文 > 详细

chapter 01

时间:2014-06-09 16:18:09      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

hibernate.cfg.xml

 

bubuko.com,布布扣
<?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>

        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
        <property name="connection.username">system</property>
        <property name="connection.password">orcl</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        
        <property name="hbm2ddl.auto">create</property>
        
        <property name="current_session_context_class">thread</property>  

        <mapping resource="com/demo/manyToMany/Project.hbm.xml"/>
        <mapping resource="com/demo/manyToMany/Employee.hbm.xml"/>

    </session-factory>

</hibernate-configuration>
bubuko.com,布布扣
bubuko.com,布布扣
package com.demo.manyToMany;

import java.util.HashSet;
import java.util.Set;

public class Employee {
    
    public Employee(){}
    public Employee(int id, String name, Set<Project> projects) {
        super();
        this.id = id;
        this.name = name;
        this.projects = projects;
    }
    
    private int id;
    private String name;
    private Set<Project> projects = new HashSet<Project>();
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Set<Project> getProjects() {
        return projects;
    }
    public void setProjects(Set<Project> projects) {
        this.projects = projects;
    }
}
bubuko.com,布布扣
bubuko.com,布布扣
<?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
    package="com.demo.manyToMany">

    <class name="Employee" table="Employee">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">seq_projectSys_employee</param>
            </generator>
        </id>
        <property name="name"/>
        <set name="projects" table="EmployeeProject" inverse="true">
            <key column="employee_id" />
            <many-to-many class="Project" column="project_id" />
        </set>
    </class>

</hibernate-mapping>
bubuko.com,布布扣
bubuko.com,布布扣
package com.demo.manyToMany;

import java.util.HashSet;
import java.util.Set;

public class Project {
    
    public Project(){}
    public Project(int id, String name, Set<Employee> employees) {
        super();
        this.id = id;
        this.name = name;
        this.employees = employees;
    }
    private int id;
    private String name;
    private Set<Employee> employees = new HashSet<Employee>();
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Set<Employee> getEmployees() {
        return employees;
    }
    public void setEmployees(Set<Employee> employees) {
        this.employees = employees;
    }
    
}
bubuko.com,布布扣
bubuko.com,布布扣
<?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
    package="com.demo.manyToMany">

    <class name="Project" table="Project">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">seq_projectSys_project</param>
            </generator>
        </id>
        <property name="name"/>
        <set name="employees" table="EmployeeProject">
            <key column="project_id" />
            <many-to-many class="Employee" column="employee_id" />
        </set>
    </class>

</hibernate-mapping>
bubuko.com,布布扣

 

chapter 01,布布扣,bubuko.com

chapter 01

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/Donie/p/3776387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!