asii
发贴: 2
积分: 0
|
于 2007-11-20 19:29
现在大部份使用都是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 INFO [main] - Echoing all SQL to stdout INFO [main] - Statistics: disabled INFO [main] - Deleted entity synthetic identifier rollback: disabled INFO [main] - Default entity-mode: pojo INFO [main] - building session factory WARN [main] - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Program%20Files/MyEclipse%205.5.1%20GA/myeclipse/eclipse/plugins/com.genuitec.org.hibernate.eclipse_5.5.0/myeclipse-data/3.0/lib/ehcache-1.1.jar!/ehcache-failsafe.xml INFO [main] - Not binding factory to JNDI, no JNDI name configured Hibernate: insert into success.manager (name, password, powerId, departmentId, createtime, createId) values (?, ?, ?, ?, ?, ?) Success
如上结果,显示了 Hibernate: insert into success.manager (name, password, powerId, departmentId, createtime, createId) values (?, ?, ?, ?, ?, ?)
而且也打印出了“Success”但是到数据库里去看,就是死活没有数据,被气死。大家麻烦看看,问题是出在哪里?
|