POJO类:
package Hibernate;
public class Deli1 {
private int id;
private String name;
public Deli1(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
映射文件:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="Hibernate.Deli1" table="deli1">
<id name="id" >
<generator class="increment">
</generator>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="connection.url">
jdbc:mysql://localhost:3306/myecport_db
</property>
<property name="connection.username">root</property>
<property name="connection.password">mysql</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="show_sql">true</property>
<mapping resource="Hibernate/A.hbm.xml" />
</session-factory>
</hibernate-configuration>
TEST 文件:
package Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Deli1Test {
public static void main(String[] args) {
System.out.println("********");
Configuration config = new Configuration().configure("Hibernate/hibernate.cfg.xml");
SessionFactory sessionfactory=config.buildSessionFactory();
Session session=sessionfactory.openSession();
Transaction tx=session.beginTransaction();
Deli1 deli=new Deli1();
deli.setName("xiaoliu");
session.save(deli);
tx.commit();
session.close();
}
}
SQL:
CREATE TABLE deli(
id integer(10) primary key,
name varchar(10) not null
);
出现的异常:
Exception in thread "main" java.lang.ClassFormatError: Illegal exception table range in class file org/hibernate/cfg/HbmBinder
谢谢高手帮忙解决一下!!!!
--转自