麻烦帮忙看一下,hibernate的save操作执行了,但是数据却没有被插入
现在大部份使用都是Hibernate+spring,今天尝试了一下用纯Hibernate进行数据库操作:
public class Manager implements java.io.Serializable {
private Integer id;
private String name;
private String password;
private Integer powerId;
private Integer departmentId;
private Date createtime;
private Integer createId;
get*();
set*();//所有的geter和seter
}
public class test {
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.configure("/HibernateSpringTest/hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
// TODO Auto-generated method stub
Manager manager = new Manager();
manager.setName("asii");
manager.setPassword("111111");
manager.setPowerId(1);
manager.setCreateId(1);
manager.setCreatetime(new Date());
manager.setDepartmentId(1);
session.save(manager);
// HibernateSessionFactory.getSession().save(manager);
// HibernateSessionFactory.closeSession();
System.out.print("Success");
}
}
执行结果是:
INFO [main] - Hibernate 3.1.3
INFO [main] -
hibernate.properties not found INFO [main] - using CGLIB reflection optimizer
INFO [main] - using JDK 1.4 java.sql.Timestamp handling
INFO [main] - configuring from resource: /HibernateSpringTest/hibernate.cfg.xml
INFO [main] - Configuration resource: /HibernateSpringTest/hibernate.cfg.xml
INFO [main] - Reading mappings from resource: hibernate/Manager.hbm.xml
INFO [main] - Mapping class: hibernate.Manager -> manager
INFO [main] - Configured SessionFactory: null
INFO [main] - Using Hibernate built-in connection pool (not for production use!)
INFO [main] - Hibernate connection pool size: 20
INFO [main] - autocommit mode: false
INFO [main] - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/success
INFO [main] - connection properties: {user=root, password=****}
INFO [main] - RDBMS: MySQL, version: 5.0.18-nt
INFO [main] - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.10 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
INFO [main] - Using dialect: org.hibernate.dialect.MySQLDialect
INFO [main] - Using default transaction strategy (direct JDBC transactions)
INFO [main] - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO [main] - Automatic flush during beforeCompletion(): disabled
INFO [main] - Automatic session close at end of transaction: disabled
INFO [main] - JDBC batch size: 15
INFO [main] - JDBC batch updates for versioned data: disabled
INFO [main] - Scrollable result sets: enabled
INFO [main] - JDBC3 getGeneratedKeys(): enabled
INFO [main] - Connection release mode: auto
INFO [main] - Maximum outer join fetch depth: 2
INFO [main] - Default batch fetch size: 1
INFO [main] - Generate SQL with comments: disabled
INFO [main] - Order SQL updates by primary key: disabled
INFO [main] - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO [main] - Using ASTQueryTranslatorFactory
INFO [main] - Query language substitutions: {}
INFO [main] - Second-level cache: enabled
INFO [main] - Query cache: disabled
INFO [main] - Cache provider: org.hibernate.cache.EhCacheProvider
INFO [main] - Optimize cache for minimal puts: disabled
INFO [main] - Structured second-level cache entries: disabled