gpt4 book ai didi

java - hibernate项目类文件com/mysql/jdbc/PreparedStatement中的代码段长度错误

转载 作者:行者123 更新时间:2023-12-01 12:56:59 25 4
gpt4 key购买 nike

我正在运行 Hibernate 项目....并收到错误

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ClassFormatError: Code segment has wrong length in class file com/mysql/jdbc/PreparedStatement
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
at com.org.main.HibernateTest.main(HibernateTest.java:21)

我的学生类(class)

package com.org.rani;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Student {

@Id
private int studId;
@Column
private String studName;
@Column
private String studAddress;

public int getStudId() {
return studId;
}

public void setStudId(int studId) {
this.studId = studId;
}

public String getStudName() {
return studName;
}

public void setStudName(String studName) {
this.studName = studName;
}

public String getStudAddress() {
return studAddress;
}

public void setStudAddress(String studAddress) {
this.studAddress = studAddress;
}

}

我的 hibernate.cfg.xml 文件

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties-->

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306
/School</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>

<mapping class="com.org.rani.Student"/>

</session-factory>

</hibernate-configuration>

我的 HibernateTest 类

package com.org.main;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.org.rani.Student;

public class HibernateTest {

/**
* @param args
*/
public static void main(String[] args) {
Student st = new Student();
st.setStudId(1);
st.setStudName("Rinki");
st.setStudAddress("Bangalore");
SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
Session session=sf.openSession();
session.beginTransaction();
session.save(st);
session.close();
}
}

最佳答案

我用“mysql-connector-java-5.1.18-bin”替换了mysql-connector.jar“mysql-connector-java-5.1.6-bin”,现在我可以进行事务了..

关于java - hibernate项目类文件com/mysql/jdbc/PreparedStatement中的代码段长度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23797756/

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