gpt4 book ai didi

java - 面对 hibernate 错误 : Caused by: java. lang.ClassNotFoundException : net. bytebuddy.NamingStrategy$SuffixingRandom$BaseNameResolver

转载 作者:行者123 更新时间:2023-11-29 04:17:31 32 4
gpt4 key购买 nike

在 Eclipse 中运行此代码时出现错误。我已经创建了 Student.java 文件:

public class Student {
private int id;
private String name;
private String email;
private int marks;

// getters/setters
}

我已经创建了 Student.hbm.xml 文件:

<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="bean.Student" table="student">
<id name="id" column="sid"></id>
<property name="name" column="sname"></property>
<property name="email" column="semail"></property>
<property name="marks" column="smarks"></property>
</class>
</hibernate-mapping>

我已经创建了 hibernate.cfg.xml 文件:

 <!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:wind</property>
<property name="connection.username">localuser</property>
<property name="connection.password">localuser</property>
<property name="connection.poolsize">5</property>

<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<mapping resource="resources/student.hbm.xml"/>

</session-factory>
</hibernate-configuration>

我已经创建了 client.java 文件:

    package testclass;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import bean.Student;

public class Client {
public static void main(String[] args) {

Student st = new Student();
st.setId(11);
st.setEmail("swapnilgthaware@gmail.com");
st.setMarks(98);
st.setName("Swapnil");

// Student object is transient here..
// When it is attached to hibernate object then it will become persistent object.


Configuration cfg = new Configuration();
cfg.configure("resources/hibernate.cfg.xml");

SessionFactory sf = cfg.buildSessionFactory();
Session s =sf.openSession();

s.save(st);

// Student object is persisten now. Even gc() will not take away this object

s.beginTransaction().commit();
// Student object will goto Database side.

s.evict(st);
}
}

我尝试添加许多 jars 文件,但我无法在我的 oracle 数据库中看到学生记录。

完整错误:

    Jul 17, 2018 8:11:09 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.3.2.Final}
Jul 17, 2018 8:11:09 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Exception in thread "main" java.lang.NoClassDefFoundError: net/bytebuddy/NamingStrategy$SuffixingRandom$BaseNameResolver
at org.hibernate.cfg.Environment.buildBytecodeProvider(Environment.java:357)
at org.hibernate.cfg.Environment.buildBytecodeProvider(Environment.java:352)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:246)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:78)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:67)
at org.hibernate.cfg.Configuration.reset(Configuration.java:158)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:124)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:118)
at testclass.Client.main(Client.java:21)
Caused by: java.lang.ClassNotFoundException: net.bytebuddy.NamingStrategy$SuffixingRandom$BaseNameResolver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more

最佳答案

我对这个库有同样的问题。

在 Java 构建路径(项目属性)中,您是将 jar 文件添加到模块路径还是类路径?我最初在模块路径下添加了 jar 。在调试问题时,我决定将 jars 移到 Classpath 中。这解决了问题。

另一种选择是将项目转换为 Maven 项目

  1. 在包资源管理器中右键单击项目名称

  2. 向下滚动到配置

  3. 选择转换为 Maven 项目

  4. 接受所有默认值并单击完成

关于java - 面对 hibernate 错误 : Caused by: java. lang.ClassNotFoundException : net. bytebuddy.NamingStrategy$SuffixingRandom$BaseNameResolver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51384547/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com