私は休止状態が初めてです。Hibernate を使用して単純なデータベース駆動型アプリケーションを作成しようとしています。しかし、私は立ち往生しています。単純なデータベース クエリを実行することさえできません。このエラーが発生しています:
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>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/dbtest </property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">pass</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="current_session_context_class">thread</property>
<property name = "show_sql">true</property>
<property name = "format_sql">true</property>
<property name = "hibernate.transaction.factory_class">org.hibernate.testing.cache.CachingRegionFactory
</property>
<property name = "hibernate.hbm2ddl.auto">create</property>
<mapping resource="com/enroll/hibernate.hbm.xml"></mapping>
<mapping class = "com/enroll/insert"></mapping>
</session-factory>
</hibernate-configuration>
hibernate.hbm.xml:
<?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 catalog="user" name="com.enroll.UserDetail" table="users"/>
<id column="id" name="id" type="java.lang.Integer">
<generator class="assigned"/>
</id>
<property column="uname" name="uname" type="string"/>
<property column="pword" name="pword" type="string"/>
</hibernate-mapping>
UserDetail.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.enroll;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class UserDetail {
@Id private int id;
String uname;
String pword;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPword() {
return pword;
}
public void setPword(String pword) {
this.pword = pword;
}
}
挿入.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.enroll;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class insert {
public static void main(String[] args){
UserDetail user1 = new UserDetail();
user1.setId(7);
user1.setUname("shri");
user1.setPword("password");
SessionFactory sf = (SessionFactory) new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(user1);
session.getTransaction().commit();
}
}
Can any one please tell me where I am wrong and what I should do?
[1]: http://i.stack.imgur.com/YbJxA.png