hibernate---注释 ----(购物:人顾客售货员boss)

package com.ij34.dao;

import javax.persistence.*;

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="people_inf")
public class People{

    @Id @Column(name="people_id")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private char gender;
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name="country" ,
        column[email protected](name="address_country")),
        @AttributeOverride(name="detail",
        column[email protected](name="address_detail")),
        @AttributeOverride(name="zip" ,
         column[email protected](name="address_zip"))

    })
    private Address address;
    public People(String name,char gender){

        this.name=name;
        this.gender=gender;
    }
    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;
    }
    public char getGender() {
        return gender;
    }
    public void setGender(char gender) {
        this.gender = gender;
    }
    public Address getAddress() {
        return address;
    }
    public void setAddress(Address address) {
        this.address = address;
    }

}

package com.ij34.dao;

public class Address{
   private String country;
   private String detail;
   private String zip;

   public Address() {
    // TODO Auto-generated constructor stub
}
    public Address(String country,String detail,String zip){
        this.country=country;
        this.detail=detail;
        this.zip=zip;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

}

package com.ij34.dao;

import javax.persistence.*;

@Entity
@Table(name="custer_inf")
public class Customers extends People{

private String content;
  @ManyToOne(cascade=CascadeType.ALL,targetEntity=Emplopes.class)
  @JoinColumn(name="emploee_id",nullable=true)
  private Emplopes emplopee;
public Customers(String name,char gender) {
    // TODO Auto-generated constructor stub
    super( name, gender);
}
public String getContent() {
    return content;
}
public void setContent(String content) {
    this.content = content;
}
public Emplopes getEmplopes() {
    return emplopee;
}
public void setEmplopes(Emplopes emplopee) {
    this.emplopee = emplopee;
}

}

package com.ij34.dao;

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

import javax.persistence.*;

@Entity
@Table(name="emplopee_inf")
public class Emplopes extends People{

public Emplopes(String name, char gender) {
        super(name, gender);
        // TODO Auto-generated constructor stub
    }
private String title;
 private double salary;
  @OneToMany(cascade=CascadeType.ALL,targetEntity=Customers.class ,mappedBy="emplopee")
 private Set<Customers> customers=new HashSet<>();
  @ManyToOne(cascade=CascadeType.ALL,targetEntity=Manager.class)
  @JoinColumn(name="manager_id",nullable=true)
  private Manager manager;

public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}
public double getSalary() {
    return salary;
}
public void setSalary(double salary) {
    this.salary = salary;
}
public Set<Customers> getCustomers() {
    return customers;
}
public void setCustomers(Set<Customers> customers) {
    this.customers = customers;
}
public Manager getManager() {
    return manager;
}
public void setManager(Manager manager) {
    this.manager = manager;
}

}

package com.ij34.dao;

import java.util.*;

import javax.persistence.*;

@Entity
@Table(name="manager_inf")
public class Manager extends Emplopes{

    public Manager(String name, char gender) {
        super( name, gender);
        // TODO Auto-generated constructor stub
    }
    private String department;
    @OneToMany(cascade=CascadeType.ALL ,targetEntity=Emplopes.class,mappedBy="manager")
    private Set<Emplopes> emplopee=new HashSet<>();

    public String getDepartment() {
        return department;
    }
    public void setDepartment(String department) {
        this.department = department;
    }
    public Set<Emplopes> getEmplopee() {
        return emplopee;
    }
    public void setEmplopee(Set<Emplopes> emplopee) {
        this.emplopee = emplopee;
    }

}

package com.ij34.web;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.service.*;

import com.ij34.dao.*;

    public class test01 {
    public static void main(String[] args)throws Exception {
    //实例化Configuration
    Configuration conf=new Configuration().configure();
    ServiceRegistry SR=new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();
    // 以Configuration实例创建SessionFactory实例
    SessionFactory SF=conf.buildSessionFactory(SR);
    //create session
    Session session=SF.openSession();
    //start 事务
    Transaction tx=session.beginTransaction();
       Emplopes li=new Emplopes("li bai", ‘男‘);
         li.setSalary(14555);
         li.setTitle("22222222262666asfa");
         li.setAddress(new Address("China", "jhaofaofoa", "12.zip"));
         Emplopes li2=new Emplopes("LI 2", ‘女‘);
         li2.setTitle("li2 two");
         li2.setSalary(222000);
         li2.setAddress(new Address("UK", "wu li2","li2.zip"));
         Manager manager=new Manager("li Manager",‘女‘);
         manager.setDepartment("JING LI BU");
         manager.setSalary(6600);
         manager.setAddress(new Address("USA", "fsucs", "usa.zip"));
         li.setManager(manager);
         Customers c=new Customers("customers", ‘女‘);
         c.setContent("IIMMM  C");
         c.setAddress(new Address("China", "im cuseter", "cu.zip"));
         c.setEmplopes(li);
         People p=new People("LIN y", ‘g‘);
         p.setAddress(new Address("China", "china people", "china.zip"));
         session.save(manager);
         session.save(p);
         session.persist(li);
         session.persist(li2);
         session.save(c);
    tx.commit();
    session.close();
    SF.close();
    }
    }

<?xml version=‘1.0‘ encoding=‘utf-8‘?>
<!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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>

<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

<property name="show_sql">true</property>

<property name="hbm2ddl.auto">update</property>

<mapping class="com.ij34.dao.Customers"/>
<mapping class="com.ij34.dao.Emplopes"/>
<mapping class="com.ij34.dao.People"/>
<mapping class="com.ij34.dao.Manager"/>
</session-factory>

</hibernate-configuration>

**********************************************************

十月 19, 2016 1:22:19 上午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
十月 19, 2016 1:22:19 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
十月 19, 2016 1:22:19 上午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
十月 19, 2016 1:22:19 上午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
十月 19, 2016 1:22:19 上午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
十月 19, 2016 1:22:19 上午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
十月 19, 2016 1:22:19 上午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
十月 19, 2016 1:22:19 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
十月 19, 2016 1:22:19 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hibernate]
十月 19, 2016 1:22:19 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
十月 19, 2016 1:22:19 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
十月 19, 2016 1:22:19 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Wed Oct 19 01:22:19 CST 2016 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
十月 19, 2016 1:22:19 上午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
十月 19, 2016 1:22:20 上午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
十月 19, 2016 1:22:20 上午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
十月 19, 2016 1:22:20 上午 org.hibernate.tuple.PojoInstantiator <init>
INFO: HHH000182: No default (no-argument) constructor for class: com.ij34.dao.People (class must be instantiated by Interceptor)
十月 19, 2016 1:22:20 上午 org.hibernate.tuple.PojoInstantiator <init>
INFO: HHH000182: No default (no-argument) constructor for class: com.ij34.dao.Customers (class must be instantiated by Interceptor)
十月 19, 2016 1:22:20 上午 org.hibernate.tuple.PojoInstantiator <init>
INFO: HHH000182: No default (no-argument) constructor for class: com.ij34.dao.Emplopes (class must be instantiated by Interceptor)
十月 19, 2016 1:22:20 上午 org.hibernate.tuple.PojoInstantiator <init>
INFO: HHH000182: No default (no-argument) constructor for class: com.ij34.dao.Manager (class must be instantiated by Interceptor)
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: custer_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: emplopee_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: manager_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: custer_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: emplopee_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: manager_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: custer_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: emplopee_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: manager_inf
十月 19, 2016 1:22:20 上午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_inf
十月 19, 2016 1:22:27 上午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: insert into people_inf (address_country, address_detail, address_zip, gender, name) values (?, ?, ?, ?, ?)
Hibernate: insert into emplopee_inf (manager_id, salary, title, people_id) values (?, ?, ?, ?)
Hibernate: insert into manager_inf (department, people_id) values (?, ?)
Hibernate: insert into people_inf (address_country, address_detail, address_zip, gender, name) values (?, ?, ?, ?, ?)
Hibernate: insert into people_inf (address_country, address_detail, address_zip, gender, name) values (?, ?, ?, ?, ?)
Hibernate: insert into emplopee_inf (manager_id, salary, title, people_id) values (?, ?, ?, ?)
Hibernate: insert into people_inf (address_country, address_detail, address_zip, gender, name) values (?, ?, ?, ?, ?)
Hibernate: insert into emplopee_inf (manager_id, salary, title, people_id) values (?, ?, ?, ?)
Hibernate: insert into people_inf (address_country, address_detail, address_zip, gender, name) values (?, ?, ?, ?, ?)
Hibernate: insert into custer_inf (content, emploee_id, people_id) values (?, ?, ?)
十月 19, 2016 1:22:27 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/hibernate]

**********************************************

**

时间: 2024-08-10 23:29:11

hibernate---注释 ----(购物:人顾客售货员boss)的相关文章

Hibernate 注释用法

注释 到现在为止,你已经看到 Hibernate 如何使用 XML 映射文件来完成从 POJO 到数据库表的数据转换的,反之亦然.Hibernate 注释是无需使用 XML 文件来定义映射的最新方法.你可以额外使用注释或直接代替 XML 映射元数据. Hibernate 注释是一种强大的来给对象和关系映射表提供元数据的方法.所有的元数据被添加到 POJO java 文件代码中,这有利于用户在开发时更好的理解表的结构和 POJO. 如果你想让你的应用程序移植到其它 EJB 3 的 ORM 应用程序

hibernate 注释说明

1 * @Entity -- 将一个类声明为一个实体 bean(即一个持久化 POJO 2 类) 3 * @Id -- 注解声明了该实体 bean 的标识属性(对应表中的主 4 键). 5 * @Table -- 注解声明了该实体 bean 映射指定的表(table),目录 6 (catalog)和 schema 的名字 7 * @Column -- 注解声明了属性到列的映射.该注解有如下的属 8 性 9 * name 可选,列名(默认值是属性名) 10 * unique 可选,是否在该列上设置

图说hibernate注释--java里配置参数(一.1)

**************************************************************[来自我另一博文]

图说hibernate注释--xml里配置参数(一)

****************************************************************************************[来自我另一博文]

迷茫于Hibernate/JPA的人提一些建议。

想对那些"迷惑"于Java ORM框架的J2EE开发人员提一些建议,希望能够对他们 更深入的理解和运用J2EE ORM框架来提速工作有所帮助,这些建议可能显得有些"陈旧"和"肤浅", 因为最近半年我没有再过多的关注Java ORM,并且也没有继续关注J2EE领域新进展. 在合理的使用Java ORM框架之前,必须要对他们有基本的了解,以下几点是最基本的也应该需要 深刻掌握的基础: * 关键API接口的深刻理解,并且大致清楚其内部逻辑机制. * 深

Javaweb Spring几个基本注释

<div class="iteye-blog-content-contain" style="font-size: 14px"></div> 一.@Autowired注解: 如要仅仅使用此注解,需要在spring容器中声明该注解的解析Bean: <bean class="org.springframework.beans.factory.annotation.                                  

从JDBC到hibernate再到mybatis之路

一.传统的JDBC编程 在java开发中,以前都是通过JDBC(Java Data Base Connectivity)与数据库打交道的,至少在ORM(Object Relational Mapping)框架没出现之前是这样,目前常用的ORM框架有JPA.hibernate.mybatis.spring jdbc等,我一开始也是使用JDBC编程,后面开始使用hibernate,有一次开发一个CRM管理系统使用的是Spring JDBC操作数据库,但个人还是不太喜欢这个框架,本人目前使用的最多还是

Hibernate (开放源代码的对象关系映射框架)介绍

Hibernate (开放源代码的对象关系映射框架) 编辑 Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQL语句,自动执行,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库. Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的Web应用中使用,最具革命意义的是,Hiberna

(摘要)100个伟大的商业理念:理念24:雇员—顾客利益链

理念24 雇员—顾客利益链 美国西尔斯百货公司(Sears)把雇员的表现和公司的业绩直接联系起来,这为我们提供了极好的例子.雇员—顾客利益链(服务利益链的变体)使得因果关系极为清楚.通过让雇员们了解他们的行动意味着什么,从而改变他们的思维方式,以及如何看待他们获得的结果. 理念 管理者传统的做法是只看重结果.然而,这种衡量方式已经成了过去.如今对市场管理的要求是强调价值驱动因素(商业活动中显示出巨大差异,能给顾客提供最大利益的各个方面)的管理.在这些价值驱动因素中,员工流动率.员工满意度.及员工