<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    鷹翔宇空

    學習和生活

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      110 Posts :: 141 Stories :: 315 Comments :: 1 Trackbacks
    摘自:http://forum.javaeye.com/viewtopic.php?t=176

    test.java
    java代碼: 


    package hibernatedemo;

    import hibernatedemo.person;
    import java.util.*;

    import net.sf.hibernate.Query;
    import net.sf.hibernate.Session;
    import net.sf.hibernate.SessionFactory;
    import net.sf.hibernate.cfg.Configuration;
    import net.sf.hibernate.tool.hbm2ddl.SchemaExport;

    public class Test {
    public static void main(String[] args) throws Exception {
       Configuration cfg = new Configuration().addClass(person.class);
       SessionFactory sessions = cfg.buildSessionFactory();
       new SchemaExport(cfg).create(true, true);
       Session s = sessions.openSession();
       Query q = s.createQuery("from person");
       for (Iterator it = q.iterate();it.hasNext();){
         person b = (person)it.next();
         System.out.println("##name:"+b.getName());
       }
    }
    }


    person.java
    java代碼: 

    package hibernatedemo;

    public class person {
      private String name;
      private String address;
      private String id;
      public person(){

      }
      public String getId() {
        return id;
      }
      public void setId(String id) {
        this.id = id;
      }
      public String getName() {
        return name;
      }
      public void setName(String name) {
        this.name = name;
      }
      public String getAddress() {
        return address;
      }
      public void setAddress(String address) {
        this.address = address;
      }
    }


    person.hbm.xml
    java代碼: 

    <?xml version="1.0"?>

    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

    <hibernate-mapping>
      <class name="hibernatedemo.person" >
        <id  name="id"
             column="id"
             type="java.lang.String">
          <generator
             class="assigned"/>   
        </id>
        <property
             name="name"
             type="java.lang.String"
             column="name"/>
        <property
             name="address"
             type="java.lang.String"
             column="pass"/>
      </class>       
    </hibernate-mapping>


    數據庫是mysql,服務器tomcat
    執行的時候控制臺信息
    java代碼: 


    2003-9-16 10:36:12 net.sf.hibernate.cfg.Environment <clinit>

    信息: Hibernate 2.1 beta 3

    2003-9-16 10:36:12 net.sf.hibernate.cfg.Environment <clinit>

    信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://localhost/hibernatedb, hibernate.connection.password=, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1}

    2003-9-16 10:36:12 net.sf.hibernate.cfg.Environment <clinit>

    信息: using java.io streams to persist binary types

    2003-9-16 10:36:12 net.sf.hibernate.cfg.Environment <clinit>

    信息: using CGLIB reflection optimizer

    2003-9-16 10:36:12 net.sf.hibernate.cfg.Configuration addClass

    信息: Mapping resource: hibernatedemo/person.hbm.xml

    2003-9-16 10:36:15 net.sf.hibernate.cfg.Binder bindRootClass

    信息: Mapping class: hibernatedemo.person -> person

    2003-9-16 10:36:15 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing one-to-many association mappings

    2003-9-16 10:36:15 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing one-to-one association property references

    2003-9-16 10:36:15 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing foreign key constraints

    2003-9-16 10:36:15 net.sf.hibernate.dialect.Dialect <init>

    信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect

    2003-9-16 10:36:15 net.sf.hibernate.cfg.SettingsFactory buildSettings

    信息: Use outer join fetching: true

    2003-9-16 10:36:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: Using Hibernate built-in connection pool (not for production use!)

    2003-9-16 10:36:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: Hibernate connection pool size: 1

    2003-9-16 10:36:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernatedb

    2003-9-16 10:36:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: connection properties: {user=root, password=}

    2003-9-16 10:36:15 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup

    信息: No TransactionManagerLookup configured (use of process level read-write cache is not recommended)

    2003-9-16 10:36:16 net.sf.hibernate.cfg.SettingsFactory buildSettings

    信息: Use scrollable result sets: true

    2003-9-16 10:36:16 net.sf.hibernate.cfg.SettingsFactory buildSettings

    信息: Query language substitutions: {no='N', true=1, yes='Y', false=0}

    2003-9-16 10:36:16 net.sf.hibernate.cfg.SettingsFactory buildSettings

    信息: cache provider: net.sf.hibernate.cache.JCSCacheProvider

    2003-9-16 10:36:16 net.sf.hibernate.cfg.Configuration configureCaches

    信息: instantiating and configuring caches

    2003-9-16 10:36:16 net.sf.hibernate.impl.SessionFactoryImpl <init>

    信息: building session factory

    2003-9-16 10:36:18 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance

    信息: no JNDI name configured

    2003-9-16 10:36:18 net.sf.hibernate.dialect.Dialect <init>

    信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect

    2003-9-16 10:36:18 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing one-to-many association mappings

    2003-9-16 10:36:18 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing one-to-one association property references

    2003-9-16 10:36:18 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing foreign key constraints

    2003-9-16 10:36:18 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing one-to-many association mappings

    2003-9-16 10:36:18 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing one-to-one association property references

    2003-9-16 10:36:18 net.sf.hibernate.cfg.Configuration secondPassCompile

    信息: processing foreign key constraints

    2003-9-16 10:36:18 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute

    信息: Running hbm2ddl schema export

    2003-9-16 10:36:18 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute

    信息: exporting generated schema to database

    2003-9-16 10:36:18 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: Using Hibernate built-in connection pool (not for production use!)

    2003-9-16 10:36:18 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: Hibernate connection pool size: 1

    2003-9-16 10:36:18 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernatedb

    2003-9-16 10:36:18 net.sf.hibernate.connection.DriverManagerConnectionProvider configure

    信息: connection properties: {user=root, password=}

    drop table person

    create table person (
       id VARCHAR(255) not null,
       name VARCHAR(255),
       pass VARCHAR(255),
       primary key (id)
    )

    2003-9-16 10:36:18 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute

    信息: schema export complete

    2003-9-16 10:36:18 net.sf.hibernate.connection.DriverManagerConnectionProvider close

    信息: cleaning up connection pool: jdbc:mysql://localhost/hibernatedb

    2003-9-16 10:36:18 net.sf.hibernate.connection.DriverManagerConnectionProvider close

    信息: cleaning up connection pool: jdbc:mysql://localhost/hibernatedb
    posted on 2006-02-08 22:10 TrampEagle 閱讀(4686) 評論(2)  編輯  收藏 所屬分類: hibernate

    Feedback

    # re: Hibernate也可以自動建表 2009-02-22 00:41 verysky
    可惜 annotation 做的ORMapping 就不可以   回復  更多評論
      

    # re: Hibernate也可以自動建表 2009-02-22 01:18 verysky
    對不住,annotation 方式的ORMapping 是可以生成表的,我大意了.
    代碼需要改進如下:
    AnnotationConfiguration cfg = new AnnotationConfiguration().addAnnotationClass(person.class);

    注意:AnnotationConfiguration的生成方式和事物,不然出不了效果

      回復  更多評論
      

    主站蜘蛛池模板: 亚洲毛片基地日韩毛片基地| 久久久久亚洲精品男人的天堂| 亚洲卡一卡2卡三卡4卡无卡三| 免费看一级高潮毛片| 国产午夜鲁丝片AV无码免费| 亚洲性色精品一区二区在线| 在线v片免费观看视频| 亚洲乱码av中文一区二区| 成人免费午间影院在线观看| 亚洲精品国产精品| 国产真实伦在线视频免费观看| 国产精品亚洲精品久久精品| 亚洲成人影院在线观看| 国产在线观看无码免费视频| 亚洲VA中文字幕无码一二三区 | 亚洲日本国产精华液| 91免费播放人人爽人人快乐| 亚洲AV无码一区二区三区牛牛| 成人毛片手机版免费看| 国产99久久亚洲综合精品| 国产AV无码专区亚洲AV漫画| 99久久99久久精品免费观看 | 噼里啪啦电影在线观看免费高清| 在线亚洲高清揄拍自拍一品区| 国产男女性潮高清免费网站 | 亚洲AV男人的天堂在线观看| 全亚洲最新黄色特级网站 | 日韩精品视频在线观看免费| 亚洲成在人线av| 日韩中文字幕精品免费一区| 在线观看亚洲电影| 国产精品亚洲а∨无码播放| 久久久久国色AV免费看图片| 黄色网址大全免费| 亚洲乱亚洲乱淫久久| 日韩中文字幕在线免费观看| 两个人看的www免费视频| 亚洲一卡二卡三卡四卡无卡麻豆 | 成人毛片免费在线观看| 成人A毛片免费观看网站| 亚洲嫩草影院在线观看|