2

行でヌルポインタ例外が発生しています

SessionFactory sesionFactory = new Configuration().configure().buildSessionFactory() ;

何がそれを引き起こしているのでしょうか??

エラーログには次のように書かれています:

Exception in thread "main" java.lang.NullPointerException
    at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:214)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    at com.hussi.model.Main.main(Main.java:15)

私のメインクラスファイル:

package com.hussi.model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Main {
    public static void main(String[] args) 
    {
        User user = new User();
        user.setUsername("hussi");
        user.setPassword("maria");

        SessionFactory sesionFactory = new Configuration().configure().buildSessionFactory() ;
        Session session = sesionFactory.openSession();
        Transaction tr = session.beginTransaction();
        session.save(user);
        session.flush();
        session.close();
    }

}

私のモデルファイル

package com.hussi.model;

public class User 
{
    int user_id;
    String username;
    String password;

    public int getUser_id() {
        return user_id;
    }
    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }


    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }


    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public String toString()
    {
        return "username==>"+this.username+" : password==>"+this.password;
    }

}

私の user.hbm.xml ファイル

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.hussi.model.User" table="users">
         <id name="user_id" type="int" column="user_id">
            <generator class="increment" />
        </id>

        <property name="username">
            <column name="username"/>
        </property>

        <property name="password">
            <column name="password"/>
        </property>
    </class>
</hibernate-mapping>

私の休止状態の設定ファイル: hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!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>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc.mysql://localhost:3306/my_hibernate_1</property>
        <property name="connection.username">root</property>
        <property name="connecttion.password">root</property>

        <!-- Database connection settings -->
        <property name="connection.pool_size">1</property>

        <!-- MySql Dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>

        <mapping resource="user.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
4

2 に答える 2

1

hibernate config connection.url プロパティを次のように変更してみてくださいjdbc:myql

于 2013-06-30T01:39:40.337 に答える