使用hibernate在数据库中插入

时间:2011-05-03 10:47:02

标签: mysql hibernate

当我在数据库中插入时,我在控制台中有这个,我使用MySQL 5.0和hibernate2:

Hibernate: insert into employe 
(prenom, mail, adresse, tel, service, fonction, login, password
 , matricule, nom, id) 
  values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  

net.sf.hibernate.transaction.JDBCTransaction无法转换为net.sf.hibernate.odmg.Transaction

任何解决方案

在控制台:

3 mai 2011 11:55:53 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.6
3 mai 2011 11:55:53 net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
3 mai 2011 11:55:53 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
3 mai 2011 11:55:53 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from file: hibernate.cfg.xml
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: org/domain/projet/config/Employe.hbm.xml
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: org.domain.projet.config.Employe -> employe
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
3 mai 2011 11:56:07 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximim outer join fetch depth: 2
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/pfe
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=manel}
3 mai 2011 11:56:07 net.sf.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
3 mai 2011 11:56:07 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): true
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: echoing all SQL to stdout
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
3 mai 2011 11:56:07 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
3 mai 2011 11:56:07 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
3 mai 2011 11:56:07 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
3 mai 2011 11:56:07 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/pfe
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=manel}
3 mai 2011 11:56:07 net.sf.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
3 mai 2011 11:56:07 net.sf.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
3 mai 2011 11:56:07 net.sf.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
3 mai 2011 11:56:07 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
3 mai 2011 11:56:07 net.sf.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost:3306/pfe
3 mai 2011 11:56:07 net.sf.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost:3306/pfe
Inserting Record
Hibernate: insert into employe (prenom, mail, adresse, tel, service, fonction, login, password, matricule, nom, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
net.sf.hibernate.transaction.JDBCTransaction cannot be cast to net.sf.hibernate.odmg.Transaction

我尝试了不同类型的交易但是工作没有工作:(

2 个答案:

答案 0 :(得分:3)

您导入了错误的Transaction课程。查看您的import声明。

顺便说一下,认真考虑升级到hibernate 3.x

答案 1 :(得分:0)

我猜你以错误的方式创建你的交易。使用:

Transaction myTransaction = mySession.beginTransaction();

...其中mySession是您已创建的会话对象。