Это вопрос о спячке Java.
my hibernate.cfg.xml
is
<?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>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/poc</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password"/>
<mapping class="test.person" file="" jar="" package="" resource="person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Соединение с базой данных работает, и я могу исследовать базы данных и таблицы,
мой образец
person.hbm.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-mapping>
<class name="test.person" table="person">
<id name="id" type="int" column="id" >
<generator class="assigned"/>
</id>
<property name="fName">
<column name="fName" />
</property>
<property name="lName">
<column name="lName"/>
</property>
<property name="age">
<column name="age"/>
</property>
<property name="gender">
<column name="gender"/>
</property>
</class>
</hibernate-mapping>
это мой личный класс
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
public class person {
private int id;
private String fName;
private String lName;
private String gender;
private int age;
public person() {
System.out.println("person");
}
public int getId() {
return id;
}
public int getAge() {
return age;
}
public String getfName() {
return fName;
}
public String getGender() {
return gender;
}
public String getlName() {
return lName;
}
public void setId(int id) {
this.id = id;
}
public void setAge(int age) {
this.age = age;
}
public void setfName(String fName) {
this.fName = fName;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setlName(String lName) {
this.lName = lName;
}
}
Вот идет мой основной класс
package test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Test {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Session session = null;
SessionFactory sessionFactory =new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
person obj = new person();
obj.setfName("Aqif");
obj.setlName("Hamid");
obj.setAge(24);
obj.setGender("Male");
session.save(obj);
session.flush();
session.close();
}
}
Я получаю это исключение,
SEVERE: JDBC Driver class not found: org.apache.derby.jdbc.ClientDriver
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at test.Test.main(Test.java:15)
Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: org.apache.derby.jdbc.ClientDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at test.Test.main(Test.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 7 more
Java Result: 1
Пожалуйста, помогите мне разрешить эти исключения
Я не знаю, почему я получаю это исключение
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
Где, как мой hibernate.cfg.xml установлен для базы данных MySQL
EDIT:
Расположение файлов,
Он находится в корне файлов .java
C: ..... NetBeansProjects \ тест \ SRC
Это папка src моего проекта.
и файлы java находятся в
C: ..... NetBeansProjects \ тест \ SRC \ тест
Я попытался скопировать файл hibernate.cfg.xml и в другие места.