<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>

有update create validate create-drop四种属性

update 表示如果映射的类中有加的类 会自动改表

create是指如果数据库没有创表可以自动帮创

validate会在执行操作前可以先验证有没有表

create-drop是指关闭sessionfactory之后自动drop掉表

一般实际开发先建表

搭建Log4j日志环境

加入jar包

引入配置文件

Log4j.properties

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c:%L - %m%n ### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### log4j.rootLogger=warn, stdout #log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug ### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug ### log just the SQL
#log4j.logger.org.hibernate.SQL=debug ### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug ### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug ### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug ### log cache activity ###
#log4j.logger.org.hibernate.cache=debug ### log transaction activity
#log4j.logger.org.hibernate.transaction=debug ### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug ### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace

可以注释掉不想要的内容

搭建Junit环境

学习maven 加入Junit类库

新建一个test

新建Junite test case

加入注解@Test

package com.easy;

import static org.junit.Assert.*;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test; public class Teachertest {
public static SessionFactory sf = null;
@BeforeClass
public static void beforeclass(){
sf = new AnnotationConfiguration().configure().buildSessionFactory();
}
@Test
public void test() {
student su = new student();
su.setId();
su.setName("haha功");
su.setAge(); Session session = sf.openSession();
session.beginTransaction();
session.save(su);
session.getTransaction().commit();
session.close(); }
@AfterClass
public static void afterclass(){
sf.close();
}
}

按照junite测试

Hibernate 再接触 基础配置 搭建Log4j环境 Junit日志环境等的更多相关文章

  1. Hibernate 再接触 基础配置 续

    <property name="show_sql">true</property> 这句话是意思显示sql语句 <property name=&quo ...

  2. hibernate3.3.2搭建Junit日志环境

    搭建好log4j日志环境后,再来搭建Junit测试环境: 测试代码放在另外一个目录下,项目右键,new一个source folder,源代码目录,放我们的测试代码,名字test.src放源代码. 比较 ...

  3. 【自动化基础】手把手教零基础小白搭建APP的UI自动化环境

    前言 帮助零基础小白一步步搭建UI自动化环境,完成Python+Appium+模拟器/真机的UI自动化环境搭建. 环境准备: jdk1.8.0 sdk Node.js appium python Ap ...

  4. Hibernate 配置文件的基础配置

    Hibernate 配置文件主要用于配置数据库连接和 Hibernate运行时所需的各种属性 每个 Hibernate 配置文件对应一个 Configuration 对象 Hibernate.cfg. ...

  5. Hibernate 再接触 悲观锁和乐观锁

    为什么取1248 二进制 CRUD 移位效率高 在并发和效率选择一个平衡点 一般不会考虑幻读 因为我们不会再一个事务里查询两次,(只能设置为seralizable) 悲观锁和乐观锁的前提是read-u ...

  6. Hibernate 再接触 一级缓存 二级缓存 查询缓存

    缓存 就是把本来应该放在硬盘里的东西放在内存里  将来存内存里读 一级缓存: session缓存 二级缓存: sessionFactory级别的   (适合经常访问,数据量有限,改动不大) 很多的se ...

  7. Hibernate 再接触 性能优化

    Sessionclear 否则session缓存里越来越多 Java有内存泄露吗? 在语法中没有(垃圾自动回收) 但是在实际中会有 比如读文件没有关什么的 1+N问题 解决方法:把fetch设置为la ...

  8. Hibernate 再接触 CRUD

    1.save 一对多双向 package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import jav ...

  9. Hibernate 再接触 关系映射 一对一双向外键关联

    凡是双向关联必设mapped by  由对方主导 wifi.java package com.bjsxt.hibernate; import javax.persistence.Entity; imp ...

随机推荐

  1. 5 Steps to Getting Started with SharePoint Development

    5 Steps to Getting Started with SharePoint Development Here are the steps I took to getting started ...

  2. (转)打印相关_C#(PrintDocument、PrintDialog、PageSetupDialog、PrintPreviewDialog)

    原文地址:http://www.cnblogs.com/smallsoftfox/archive/2012/06/25/2562718.html 参考文章:http://www.cnblogs.com ...

  3. Elasticsearch分布式机制探究

    Elasticsearch是一套分布式的系统,分布式是为了应对大数据量隐藏了复杂的分布式机制 分片机制 shard = hash(routing) % number_of_primary_shards ...

  4. Spring获取application.properties

    方法一:@Value获取属性值 首先在application.properties中添加属性值 app.name=MyApp app.description=${app.name} is a Spri ...

  5. [work]Spring_Jdbc

    封装Spring-RowMapper,使得使用更加灵活 import java.sql.ResultSet; import java.sql.SQLException; import java.uti ...

  6. web api 本地测试

    [最简单的,本人小白,大神勿喷] 一:创建web API 服务端 ①创建web api 的项目 ②在这个api项目的Web.config中加上如下几段话: <httpProtocol>&l ...

  7. 占cpu 100%的脚本

    #! /bin/sh # filename killcpu.sh if [ $# -ne 1 ] ; then echo "USAGE: $0 <CPUs>|stop" ...

  8. 自定义UITableViewCell上的delete按钮

    http://blog.csdn.net/xiaoxuan415315/article/details/7834940

  9. windows2012系统IE浏览器无法打开加载flashplayer内容

    添加角色和功能,用户界面和基础结构,桌面体检,安装完重启电脑

  10. 白鹭引擎 - 本地坐标和舞台坐标的转化 ( globalToLocal, localToGlobal )

    class Main extends egret.DisplayObjectContainer { /** * Main 类构造器, 初始化的时候自动执行, ( 子类的构造函数必须调用父类的构造函数 ...