任何人请解决我的问题。我正在尝试将对象保存到oracle数据库(Oracle 10G)时收到java.lang.reflect.invocationTargetException。
这是我的名为Student.java的模型类
package org.hibernatetest;
public class Student {
private int id;
private String name;
private String email;
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;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
这是我的名为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="org.hibernatetest.Student" table="STUDENT_2018">
<id name="id" column="STUDENT_ID"/>
<property name="name" column="STUDENT_NAME"></property>
<property name="email" column="STUDENT_EMAIL"></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="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">Test</property>
<property name="hibernate.connection.password">Test</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="show_sql">true</property>
<mapping resource="resource/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我的名为Test.java的持久化类
package org.hibernatetest;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Test {
public static void main(String[] args) {
Student st = new Student();
st.setId(1);
st.setName("Mohan");
st.setEmail("mmohan668@gmail.com");
Configuration cfg = new Configuration();
SessionFactory sf = cfg.configure("resource/hibernate.cfg.xml").buildSessionFactory();
Session s = sf.openSession();
s.save(st);
s.beginTransaction().commit();
s.evict(st);
}
}
请帮助解决我的问题。提前谢谢。