`

Hibernate学习笔记一

阅读更多

 

在普通java应用中使用Hibernate。

代码参考自Hibernate的官方网站中文教程

http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html/tutorial.html

 

一、安装JDK 6、Eclipse、Maven 2和m2e

JDK 6

http://www.oracle.com/technetwork/java/javase/downloads/index.html

 

Eclipse Java EE

http://www.eclipse.org/

 

Apache Maven 2.2.1

http://maven.apache.org/

 

Maven Integration (M2E)

http://www.eclipse.org/m2e/

 

(关于m2e的安装问题,见另一篇日志《Maven学习记录》)

 

二、安装hsqldb

(1) 下载hsqldb_1_8_1_3.zip,创建新的文件夹hsqldb。

解压hsqldb.jar放在hsqldb文件夹中。

 

(2) 创建批处理startdb.bat(可以指定java.exe的完整路径,用引号括起)

内容如下:

"D:\java\jdk1.6.0_20\bin\java.exe" -cp hsqldb.jar org.hsqldb.Server

 

(3) 创建server.properties,内容如下:

server.database.0=file:test/test

server.dbname.0=test

server.port=9001

server.silent=true

server.trace=false

 

(4) 双击startdb.bat,自动生成test目录,并启动数据库(控制台不退出)。

开始监听9001端口(不要开多个实例以避免端口冲突)

如果测试结束可按Ctrl+C关闭数据库。

 

三、创建工程

New->Other->Maven Project->

Next->Filter:填maven-archetype-quickstart并选中->

Next->Group Id:填org.hibernate.tutorial->

Artifact Id:填hibernate-tutorial->

Package:填org.hibernate.tutorial->

Finish

 

四、修改编码格式

右键->Properties->Resource->Text file encoding->

Other填UTF-8。

修改完后m2e会自动更新pom.xml的内容

 

五、更改pom.xml

把pom.xml改成如下所示:

 

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.hibernate.tutorial</groupId>
  <artifactId>hibernate-tutorial</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>hibernate-tutorial</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>


  <!-- 上面的pom.xml片段都是用下面命令行自动生成的,并且创建了目录结构(不包括src/main/resources) -->
  <!-- 
       mvn archetype:generate 
           -DgroupId=org.hibernate.tutorial 
           -DartifactId=hibernate-tutorial 
           -DarchetypeArtifactId=maven-archetype-quickstart 
           -DinteractiveMode=false
    -->

  <!-- we dont want the version to be part of the generated war file name -->
  <!-- 我们不想让生成的war文件名中包含版本号 -->
  <!--
  <build>
    <finalName>${artifactId}</finalName>
  </build>
    -->
  
  <!-- 关闭警告 -->
  <!--
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
    -->
  
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    
    <!-- 依赖的关键字搜索在http://www.mvnbrowser.com/index.html,输入相应的库名,如hibernate-core -->
    <!-- maven的搜索引擎请参考http://maven.apache.org/general.html -->
	<dependency>
	  <groupId>org.hibernate</groupId>
	  <artifactId>hibernate-core</artifactId>
	  <version>3.3.2.GA</version>
	</dependency>
	<!-- Because this is a web app, we also have a dependency on the servlet api. -->
	<!-- 因为这是个web应用,我们也有一个对servlet api的依赖。 -->
	<dependency>
	  <groupId>javax.servlet</groupId>
	  <artifactId>servlet-api</artifactId>
	  <version>2.5</version>
	</dependency>
	<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
	<!-- Hibernate使用slf4j输出日志,这里我们只使用简单后端 -->
	<dependency>
	  <groupId>org.slf4j</groupId>
	  <artifactId>slf4j-simple</artifactId>
	  <version>1.5.6</version>
	</dependency>
	<!-- Hibernate gives you a choice of bytecode providers between cglib and javassist -->
	<!-- Hibernate让你可以选择bytecode提供者是cglib还是javassist -->
	<dependency>
	  <groupId>javassist</groupId>
	  <artifactId>javassist</artifactId>
	  <version>3.10.0.GA</version>
	</dependency>
	<dependency>
	  <groupId>hsqldb</groupId>
	  <artifactId>hsqldb</artifactId>
	  <version>1.8.0.1</version>
	</dependency>
  </dependencies>
  
  <!-- see http://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html-->
  <build>
   <!-- 资源 -->
   <!-- 保留所有.hbm.xml文件 -->
   <resources>
	<resource>
	 <filtering>false</filtering>
	 <directory>src/main/java</directory>
	 <includes>
	 <include>**/*.hbm.xml</include>
	 </includes>
    </resource>
	<!-- 保留resources下的所有文件 -->
	<resource>
	 <filtering>false</filtering>
	 <directory>src/main/resources</directory>
	 <includes>
	 <include>**/*</include>
	 </includes>
    </resource>
   </resources>
   
   <!-- 资源和编译器插件,参数设置方法见http://maven.apache.org/plugins/index.html -->
   <plugins>
    <!-- 资源插件,使用UTF-8编码 -->
    <plugin>
	  <groupId>org.apache.maven.plugins</groupId>  
	  <artifactId>maven-resources-plugin</artifactId>
	  <version>2.5</version>
	  <configuration>  
	    <encoding>UTF-8</encoding>  
	  </configuration>  
    </plugin>
    <!-- 编译器插件,使用JDK1.6,使用UTF-8编码 -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.3.2</version>
      <configuration>
        <source>1.5</source>
        <target>1.5</target>
        <encoding>UTF-8</encoding>
      </configuration>
    </plugin>
    <!-- 执行插件的java任务,参数设置方法见http://mojo.codehaus.org/exec-maven-plugin/usage.html-->
    <!-- 指定java主类和参数,用于测试 -->
    <!-- mvn clean compile后执行mvn exec:java --> 
    <!-- 如果执行命令行,则为 -->
    <!-- mvn exec:java -Dexec.mainClass="org.hibernate.tutorial.EventManager" -Dexec.args="store" -->
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.2</version>
      <executions>
        <execution>
          <goals>
            <goal>java</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <mainClass>org.hibernate.tutorial.EventManager</mainClass>
        <arguments>
          <argument>store</argument>
        </arguments>
        <!--
        <systemProperties>
          <systemProperty>
            <key>myproperty</key>
            <value>myvalue</value>
          </systemProperty>
        </systemProperties>
        -->
      </configuration>
    </plugin>
   </plugins>
  </build>
</project>

 

 

其中涉及如下问题:

(1)需要手工到网上查询依赖的版本号

(2)需要设置src/main/java和src/main/resources的过滤策略

(3)需要设置一些插件参数以支持UTF-8和方便测试

 

六、编写Java类

(参考自:http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html/tutorial.html)

 

src\main\java\org\hibernate\tutorial\EventManager.java

 

 

package org.hibernate.tutorial;

import java.util.*;
import org.hibernate.Session;
import org.hibernate.tutorial.domain.Event;
import org.hibernate.tutorial.util.HibernateUtil;

public class EventManager {
    public static void main(String[] args) {
        EventManager mgr = new EventManager();
		System.out.println("参数是" + args[0]);
        if (args[0].equals("store")) {
            mgr.createAndStoreEvent("My Event", new Date());
        } else if (args[0].equals("list")) {
            List events = mgr.listEvents();
            for (int i = 0; i < events.size(); i++) {
                Event theEvent = (Event) events.get(i);
                System.out.println(
					"Event: " + theEvent.getTitle() +
					" Time: " + theEvent.getDate());
            }
        }
        HibernateUtil.getSessionFactory().close();
    }

    private void createAndStoreEvent(String title, Date theDate) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Event theEvent = new Event();
        theEvent.setTitle(title);
        theEvent.setDate(theDate);
        session.save(theEvent);
        session.getTransaction().commit();
    }

    private List listEvents() {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        List result = session.createQuery("from Event").list();
        session.getTransaction().commit();
        return result;
    }
}

 

 

src\main\java\org\hibernate\tutorial\util\HibernateUtil.java

 

 

package org.hibernate.tutorial.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            // 从hibernate.cfg.xml中创建SessionFactory
            return new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            // 当它可能被吞食时,保证你的异常被记录到日志中
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

 

 

src\main\java\org\hibernate\tutorial\domain\Event.java

 

 

package org.hibernate.tutorial.domain;

import java.util.Date;

public class Event {
    private Long id;

    private String title;
    private Date date;

    public Event() {}

    public Long getId() {
        return id;
    }

    private void setId(Long id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

 

 

七、编写.cfg.xml和.hbm.xml配置文件

(参考自:http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html/tutorial.html)

创建src/main/resources目录

src\main\resources\hibernate.cfg.xml

 

 

<?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>
        <!-- Database connection settings -->
        <!-- 数据库连接设置 -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:hsql://localhost:9001/test</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <!-- JDBC连接池(使用内置)-->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <!-- SQL方言 -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <!-- 开启Hibernate的自动上下文管理 -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <!-- 关闭二级缓存 -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <!-- 输出所有执行SQL到stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <!-- 在启动时卸载并重新创建数据库 -->
        <property name="hbm2ddl.auto">update</property>
        <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

 

 

 

src\main\java\org\hibernate\tutorial\domain\Event.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="org.hibernate.tutorial.domain">
    <class name="Event" table="EVENTS">
        <id name="id" column="EVENT_ID">
			<generator class="native"/>
        </id>
        <property name="date" type="timestamp" column="EVENT_DATE"/>
        <property name="title"/>
    </class>
</hibernate-mapping>

 

 

八、编译运行

工程->右键->Debug As->Maven package

如果显示BUILD SUCCESS

你会看到

/hibernate-tutorial/target/hibernate-tutorial-0.0.1-SNAPSHOT.jar

这个jar文件

然后启动第二步提到的hsqldb,双击startdb.bat

工程->右键->Debug As->Maven build...->Goals->exec:java

(因为我已经在pom.xml定义了参数,所以下面不用添加参数)

按Run运行

显示以下内容

 

 
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hibernate-tutorial 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.2:java (default-cli) @ hibernate-tutorial ---
参数是store
0 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
0 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - hibernate.properties not found
0 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
16 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
63 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
63 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
2063 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : org/hibernate/tutorial/domain/Event.hbm.xml
4375 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.hibernate.tutorial.domain.Event -> EVENTS
4391 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
4438 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
4438 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
4438 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
4438 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost:9001/test
4438 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
4484 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 1.8.1
4484 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
4500 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
4516 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
4563 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
4719 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
4719 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
4719 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
4734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema
4734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: EVENTS
4734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: EVENTS
4734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete
Hibernate: insert into EVENTS (EVENT_ID, EVENT_DATE, title) values (null, ?, ?)
Hibernate: call identity()
4813 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.impl.SessionFactoryImpl - closing
4813 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:hsql://localhost:9001/test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.594s
[INFO] Finished at: Tue Mar 08 21:29:54 CST 2011
[INFO] Final Memory: 3M/15M
[INFO] ------------------------------------------------------------------------

 

 

如果把pom.xml中的参数store改为list,运行结果中显示刚才插入数据的时间

 

 

 

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hibernate-tutorial 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.2:java (default-cli) @ hibernate-tutorial ---
参数是list
15 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
15 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - hibernate.properties not found
15 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
15 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
109 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
109 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
1109 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : org/hibernate/tutorial/domain/Event.hbm.xml
3531 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.hibernate.tutorial.domain.Event -> EVENTS
3546 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
3625 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
3625 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
3625 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
3625 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost:9001/test
3625 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
3671 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 1.8.1
3671 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
3703 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
3718 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
3734 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
3796 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
4031 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
4031 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
4031 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
4031 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema
4062 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.TableMetadata - table found: PUBLIC.EVENTS
4062 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.TableMetadata - columns: [title, event_date, event_id]
4062 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.TableMetadata - foreign keys: []
4062 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.TableMetadata - indexes: [sys_idx_47]
4062 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete
Hibernate: select event0_.EVENT_ID as EVENT1_0_, event0_.EVENT_DATE as EVENT2_0_, event0_.title as title0_ from EVENTS event0_
Event: My Event Time: 2011-03-08 21:29:49.781
4343 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.impl.SessionFactoryImpl - closing
4343 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:hsql://localhost:9001/test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.156s
[INFO] Finished at: Tue Mar 08 21:32:44 CST 2011
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------

 

 
分享到:
评论

相关推荐

    一个使用Androidstudio开发的校园通知APP

    一个使用AndroidStudio开发的校园通知APP,支持注册登录,支持聊天,后端技术:http get post 方法(分别有json数据格式和form数据格式),websocket长连接,用于接收消息,mqtt协议用于查看数据。

    基于粒子群的ieee30节点优化、配电网有功-无功优化 软件:Matlab+Matpowre 介绍:对配电网中有功-无功协调优化调度展开研究,通过对光伏电源、储能装置、无功电源和变压器分接头等设备协调

    基于粒子群的ieee30节点优化、配电网有功-无功优化 软件:Matlab+Matpowre 介绍:对配电网中有功-无功协调优化调度展开研究,通过对光伏电源、储能装置、无功电源和变压器分接头等设备协调控制,以实现光伏利用率最大、网络损耗最小、电压质量最优的综合优化目标。 采用粒子群算法寻求最优解,得到配电网的调控策略,从而制定合理的优化运行方案。 最后通过算例分析,说明其合理性。 Matpowre(需要Matpowre请安装不然会有错)

    C#自定义事件 2024年12月23日

    通过自定义事件来传值。此种方法适合于写驱动程序。进行数据采集。 对于一般的系统事件,是有两个参数的,一个是sender,一个是EventArgs,对于sender,个事件的触发者,一般指向的是一个控件,但是对于EventArgs,一般常用来传递鼠标位置等信息,下面就自定义事件传值就是通过EventArgs来实现。 通过EventArgs来实现传值,我们首先需要创建一个类,继承EventArgs,我们可以将需要传递的数据,直接在类里面定义成属性,这里以传递一个布尔(没有再最终的代码内使用)、一个浮点数,一个字符串为例,

    基于校园的互帮互助社交APP全部资料+详细文档+高分项目.zip

    【资源说明】 基于校园的互帮互助社交APP全部资料+详细文档+高分项目.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!

    Download usage

    Download usage

    基于高德地图的校园导航全部资料+详细文档+高分项目.zip

    【资源说明】 基于高德地图的校园导航全部资料+详细文档+高分项目.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!

    健康中国2030框架下智慧医药医疗博览会方案

    内容概要:本文介绍了 2020 京东健康智慧医药医疗博览会在湖南长沙举办的总体方案。该方案详细描述了展会的背景、目标、组织机构、展区规模和内容、主体活动、拟邀嘉宾及宣传媒体等内容。展会旨在展示互联网+医疗健康生态下的新技术、新产品和新方案,推动智慧医疗产业链的数据化、信息化和智慧化建设,为健康中国战略和健康湖南行动贡献力量。 适合人群:医疗行业的从业人员、智慧医疗技术开发者、政府相关部门、健康产业投资人等。 使用场景及目标:① 通过展会展示先进的医药医疗技术和产品,促进技术交流与合作;② 推动智慧医疗产业发展,助力健康中国战略和健康湖南行动的实施;③ 提高人民群众的健康水平和医疗服务质量。 其他说明:此次展会将设置十大展区,涵盖健康管理、智慧医院、精准医疗、智能穿戴、移动医疗系统、智能养老等多个方面,同期还将举办多场论坛和商务活动。

    qt开发类似于网盘的项目

    C/S架构,C++开发的,使用UDP协议

    2023-04-06-项目笔记 - 第三百五十六阶段 - 4.4.2.354全局变量的作用域-354 -2025.12.23

    2023-04-06-项目笔记-第三百五十六阶段-课前小分享_小分享1.坚持提交gitee 小分享2.作业中提交代码 小分享3.写代码注意代码风格 4.3.1变量的使用 4.4变量的作用域与生命周期 4.4.1局部变量的作用域 4.4.2全局变量的作用域 4.4.2.1全局变量的作用域_1 4.4.2.354局变量的作用域_354- 2024-12-23

    基于Bmob后台搭建的一块校园社区类APP,内置二手交易模块全部资料+详细文档+高分项目.zip

    【资源说明】 基于Bmob后台搭建的一块校园社区类APP,内置二手交易模块全部资料+详细文档+高分项目.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!

    高校学生求职就业平台(编号:24440246).zip

    高校学生求职就业平台(编号:24440246).zip

    Python与Pygame实现带特效的圣诞节场景模拟程序

    内容概要:本文详细介绍如何使用Python结合Pygame库制作一个充满圣诞气息的应用程序。该程序包括生成雪花、圣诞树以及闪烁星星的效果,并配以背景音乐以增加节日气氛。通过具体的代码示例,指导读者逐步构建这一有趣的项目。 适用人群:对于有兴趣探索Pygame图形库及游戏开发的基础开发者、编程初学者。 使用场景及目标:① 初步掌握Pygame的基本用法及其常见图形绘制方法;② 学习如何通过编程手段营造节日氛围;③ 作为个人项目或课堂作业的优秀实践。 其他说明:除了文中提供的基础功能外,鼓励读者在此基础上发挥创意,加入更多有趣的功能,比如动态改变场景中的物体、响应用户输入等,从而创造出独一无二的作品。

    计算机程序设计员三级(选择题)

    计算机程序设计员三级(选择题)

    基于Spring Boot的养老院管理系统的设计与实现_6575f5w2_223-wx(1).zip

    基于Spring Boot的养老院管理系统的设计与实现_6575f5w2_223-wx(1).zip

    数据结构排序算法:插入排序、希尔排序、冒泡排序及快速排序算法

    数据结构

    (42757812)0.96寸OLED显示屏STC8A8K64S4A12-IIC-例程

    内容来源于网络分享,如有侵权请联系我删除。另外如果没有积分的同学需要下载,请私信我。

    基于java的网上订餐系统(编号:96717170).zip

    基于java的网上订餐系统(编号:96717170).zip

    基于Java WEB旅游门票信息系统设计与实现_70rn7486_206-wx.zip

    基于Java WEB旅游门票信息系统设计与实现_70rn7486_206-wx.zip

    ST官方电机库FOC算法

    无刷电机永磁同步电机库,有感控制,无感控制库

    2024年超融合网络架构研究与实践报告.pdf

    2024年超融合网络架构研究与实践报告.pdf

Global site tag (gtag.js) - Google Analytics