Hibernate没有看到路径

时间:2018-05-29 17:56:36

标签: java hibernate

我有一些hibernate的问题。我正在分享我的代码 我得到的错误

  

" C:\ Program Files \ Java \ jdk1.8.0_161 \ bin \ java"   -Dfile.encoding = windows-1250 -jar C:\ Users \ kubci \ IdeaProjects \ FinalProject \ target \ hibernate-1.0-SNAPSHOT-jar-with-dependencies.jar       maj 29,20188 7:41:56 PM org.hibernate.Version logVersion       信息:HHH000412:休眠核心{[WORKING]}       maj 29,20188 7:41:56 PM org.hibernate.cfg.Environment       信息:HHH000206:找不到hibernate.properties       maj 29,20188 7:41:57 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager          信息:HCANN000001:Hibernate Commons Annotations {5.0.3.Final}       maj 29,20188 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   配置       警告:HHH10001002:使用Hibernate内置连接池(不用于生产!)       maj 29,20188 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   buildCreator       信息:HHH10001005:在URL [jdbc:mysql:// localhost:3306 / loginpanel]上使用驱动程序[com.mysql.jdbc.Driver]       maj 29,20188 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   buildCreator       信息:HHH10001001:连接属性:{user = root,password = ****}       maj 29,20188 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   buildCreator       信息:HHH10001003:自动提交模式:false       maj 29,20188 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl $ PooledConnections          信息:HHH000115:Hibernate连接池大小:20(min = 1)       maj 29,20188 7:41:58 PM org.hibernate.dialect.Dialect       信息:HHH000400:使用方言:org.hibernate.dialect.MySQLDialect       线程" main"中的例外情况org.hibernate.boot.registry.classloading.spi.ClassLoadingException:   无法加载类[pl.Final.Project.entities.LoginConnection]         在org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:354)         在org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl。(AnnotationMetadataSourceProcessorImpl.java:105)         在org.hibernate.boot.model.process.spi.MetadataBuildingProcess $ 1.(MetadataBuildingProcess.java:156)         在org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:150)         在org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84)         在org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474)         在org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)         在pl.Final.Project.Main.main(Main.java:19)       引起:java.lang.ClassNotFoundException:无法加载请求的类:pl.Final.Project.entities.LoginConnection         at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl $ AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:342)         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)         at java.lang.Class.forName0(Native Method)         在java.lang.Class.forName(Class.java:348)         at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:351)         ... 9更多

这是我的主。

package pl.Final.Project;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import pl.Final.Project.entities.LoginUser;

import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    private static SessionFactory factory;
    public static void main(String[] args) {
        factory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
        System.exit(0);
    }
    public static ArrayList<LoginUser> getUsersList(){
        Session session = factory.openSession();
        Transaction tx = null;
        ArrayList<LoginUser> usersArrayList= new ArrayList<>();
        try{
            tx = session.beginTransaction();
            List customerList = session.createQuery("FROM pl.Final.Project.entities.LoginUser WHERE id=1").list();
            for(Iterator iterator = customerList.iterator(); iterator.hasNext();){
                LoginUser c =(LoginUser) iterator.next();
                usersArrayList.add(c);
            }
            tx.commit();

        }catch (HibernateException e){
            if(tx!=null){
                tx.rollback();
            }
        }finally {
            session.close();
        }
        return usersArrayList;
    }
}

和cfg.xml和hmb.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM

        "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/loginpanel</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

        <mapping class="pl.Final.Project.entities.LoginConnection" />
    </session-factory>
</hibernate-configuration>

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name = "pl.Final.Project.entities.LoginUser" table = "tuser">

        <meta attribute = "class-description">
           Login Customer mapping
        </meta>

        <id name = "id" type = "int" column = "id">
            <generator class="native"/>
        </id>

        <property name = "login" column = "login" type = "string"/>
        <property name = "password" column = "password" type = "string"/>
        <property name = "name" column = "name" type = "string"/>
        <property name = "surname" column = "surname" type = "string"/>

    </class>
</hibernate-mapping>

我不知道该怎么做。我有这个代码的另一个项目,它的工作原理。我做了复制和粘贴,更改了一些细节,如路径等。有一些错误,我认为这是问题所在:

  

线程中的异常&#34; main&#34;   org.hibernate.boot.registry.classloading.spi.ClassLoadingException:   无法加载类[pl.Final.Project.entities.LoginConnection]

1 个答案:

答案 0 :(得分:0)

您遇到的异常清楚地表明无法加载LoginConnection类。然而,没有可见的LoginConnection类。您已将LoginConnection添加为Hibernate会话的映射类,但缺少LoginConnection的源代码。也许你应该首先创建LoginConnection类,然后才能加载它?

或者你是否意外地写了LoginConnection而不是LoginUser?