java-Java Hibernate运行问题
程序员文章站
2022-04-21 20:26:03
...
javahibernatejunit4mysqlconfiguration
错误信息
java.lang.NoClassDefFoundError: javax/transaction/SystemException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.jboss.logging.Logger$1.run(Logger.java:2554) at java.security.AccessController.doPrivileged(Native Method) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529) at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516) at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28) at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24) at org.hibernate.cfg.Configuration.(Configuration.java:86) at com.lee.hibernate.HibernateTest.test(HibernateTest.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)Caused by: java.lang.ClassNotFoundException: javax.transaction.SystemException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 33 more
hibernate.cfg.xml
root root com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/hibernate org.hibernate.dialect.MySQLInnoDBDialect true true create
News.hbm.xml
News.java
package com.lee.hibernate;import java.sql.Date;public class News { private Integer id; private String title; private String author; private Date date; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public News() { super(); } public News(String title, String author, Date date) { super(); this.title = title; this.author = author; this.date = date; } @Override public String toString() { return "News [id=" + id + ", title=" + title + ", author=" + author + ", date=" + date + "]"; }}
HibernateTest.java
package com.lee.hibernate;import java.sql.Date;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;//import org.hibernate.boot.registry.StandardServiceRegistryBuilder;import org.hibernate.cfg.Configuration;//import org.hibernate.service.ServiceRegistry;import org.junit.Test;public class HibernateTest { @Test public void test() { //1 创建一个SessionFactory对象 SessionFactory sessionFactory = null; //1) 创建Configuration对象: 对应hibernate的基本配置信息和对象映射信息 Configuration configuration = new Configuration().configure(); sessionFactory = configuration.buildSessionFactory(); //2)创建sessionRegistry对象: hibernate 4.x新添加的对象 //hibernate的任何配置和服务都需要在该对象注册后才能有效.// ServiceRegistry serviceRegistry = // new StandardServiceRegistryBuilder().// applySettings(configuration.getProperties())// .build(); //3)// sessionFactory = configuration.buildSessionFactory(sessionRegistry); //2 创建一个Session对象 Session session = sessionFactory.openSession(); //3 开启事务 Transaction transaction = session.beginTransaction(); //4 执行保存操作 News news = new News("Java", "Lee", new Date(new java.util.Date().getTime())); session.save(news); //5 提交事务 transaction.commit(); //6 关闭Session session.close(); //7 关闭SessionFactory对象 sessionFactory.close(); }}
hibernate框架是5.0.0.Final版本
mysql-jdbc驱动是5.1.37-bin版本
JUnit是4.10版本
Java8
Eclipse Version: Mars.1 Release (4.5.1)
Windows10
Configuration错误, 但不了解, 麻烦解答
上一篇: js判断文本框输入的内容是否为数字_javascript技巧
下一篇: JavaScript面向对象
推荐阅读
-
appium运行各种坑爹报错问题及解决方法【推荐】
-
解决运行procedure很慢但运行procedure内容很快问题
-
java Hibernate 一对多自身关联问题
-
IE运行缓慢? 5招帮你解决IE运行缓慢的问题
-
出现 “java”不是内部或外部命令,也不是可运行程序或批处理文件的问题
-
IE运行缓慢? 5招帮你解决IE运行缓慢的问题
-
会声会影运行不了遇到Ulead VideoStudio问题要关闭
-
Hibernate通过SQL查询常量时只返回第一个字符问题的解决方法
-
使用cmd运行mysql数据库的时候,报错:"不是内部命令也不是可有运行的程序"问题的解决办法
-
关于在vscode使用webpack指令显示"因为在此系统中禁止运行脚本"问题(完美解决)