做一个Hibernate小例子,出现如下问题~~~:*

Strawberry79 2004-08-06 04:56:25
我找一个hibernate的小例子,其中hibernate.properties文件如下:
## Oracle

#hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
hibernate.dialect net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
hibernate.connection.username water
hibernate.connection.password water
hibernate.connection.url jdbc:oracle:thin:@10.3.8.48:1521:ORADB

我使用的是oracle数据库

下面写了一个插入数据的类,代码如下:
public class TestPersonModel2 {

private static SessionFactory sessionFactory;

public static void main(String[] args) throws Exception{
Configuration conf= new Configuration().addClass(PersonModel.class);

//在表中插入第一条数据

sessionFactory = conf.buildSessionFactory();
Session s = sessionFactory.openSession(); *****报错*****

Transaction t = s.beginTransaction();

PersonModel p1=new PersonModel();

p1.setName("robin");
p1.setAddress("上海");

//2.持久化
s.save(p1);

//此时p1已经可以在数据库中找到
t.commit();
s.close();
}
}

输出错误信息如下:
2004-8-6 10:08:32 net.sf.hibernate.cfg.Environment <clinit>
信息: Hibernate 2.1.2
2004-8-6 10:08:32 net.sf.hibernate.cfg.Environment <clinit>
信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=water, hibernate.connection.url=jdbc:oracle:thin:@10.3.8.48:1521:ORADB, hibernate.connection.password=water, hibernate.connection.pool_size=1}
2004-8-6 10:08:32 net.sf.hibernate.cfg.Environment <clinit>
信息: using java.io streams to persist binary types
2004-8-6 10:08:32 net.sf.hibernate.cfg.Environment <clinit>
信息: using CGLIB reflection optimizer
2004-8-6 10:08:32 net.sf.hibernate.cfg.Configuration addClass
信息: Mapping resource: person/PersonModel.hbm.xml
2004-8-6 10:08:33 net.sf.hibernate.cfg.Binder bindRootClass
信息: Mapping class: person.PersonModel -> ZY_PERSON
2004-8-6 10:08:34 net.sf.hibernate.cfg.Configuration secondPassCompile
信息: processing one-to-many association mappings
2004-8-6 10:08:34 net.sf.hibernate.cfg.Configuration secondPassCompile
信息: processing one-to-one association property references
2004-8-6 10:08:34 net.sf.hibernate.cfg.Configuration secondPassCompile
信息: processing foreign key constraints
2004-8-6 10:08:34 net.sf.hibernate.dialect.Dialect <init>
信息: Using dialect: net.sf.hibernate.dialect.OracleDialect
2004-8-6 10:08:34 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Maximim outer join fetch depth: 1
2004-8-6 10:08:34 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Use outer join fetching: true
2004-8-6 10:08:34 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
信息: Using Hibernate built-in connection pool (not for production use!)
2004-8-6 10:08:34 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
信息: Hibernate connection pool size: 1
2004-8-6 10:08:34 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
信息: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.3.8.48:1521:ORADB
2004-8-6 10:08:34 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
信息: connection properties: {user=water, password=water}
2004-8-6 10:08:34 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
信息: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
2004-8-6 10:08:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Use scrollable result sets: true
2004-8-6 10:08:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Use JDBC3 getGeneratedKeys(): false
2004-8-6 10:08:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Optimize cache for minimal puts: false
2004-8-6 10:08:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Query language substitutions: {no='N', true=1, yes='Y', false=0}
2004-8-6 10:08:35 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: cache provider: net.sf.hibernate.cache.HashtableCacheProvider
2004-8-6 10:08:35 net.sf.hibernate.cfg.Configuration configureCaches
信息: instantiating and configuring caches
2004-8-6 10:08:35 net.sf.hibernate.impl.SessionFactoryImpl <init>
信息: building session factory
2004-8-6 10:08:36 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
信息: no JNDI name configured(******???)
2004-8-6 10:08:36 net.sf.hibernate.cache.UpdateTimestampsCache <init>
信息: starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
2004-8-6 10:08:36 net.sf.hibernate.cache.QueryCache <init>
信息: starting query cache at region: net.sf.hibernate.cache.QueryCache
java.lang.NoClassDefFoundError: javax/transaction/Synchronization
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:312)
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:325)
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:333)
at person.TestPersonModel2.main(TestPersonModel2.java:23)
Exception in thread "main"


请问这是什么问题?(在网上搜了许久,没有找到答案,多谢指点!)

另:hibernate.properties和hibernate.hbm.xml建议使用哪一个,有何区别,我有点概念不清
...全文
54 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Strawberry79 2004-08-06
  • 打赏
  • 举报
回复
太感谢了,的确是这么回事~!:)
yufanzx 2004-08-06
  • 打赏
  • 举报
回复
1。你的lib目录下缺少一个叫jta.jar的包
2。除了语法不同,效果完全一样

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧