hibernate mit postgreSQL

Hallo,
ich versuche mich gerade in hibernate einzuarbeiten und habe dafür versucht ein Objekt einer "Employee" Klasse in meine PostgreSQL datenbank zu laden. Allerdings erhalte ich folgenden Fehler: Exception in thread "main" org.hibernate.boot.InvalidMappingException: class org.dirtybit.Employee not found while looking for property: id

Ich arbeite mit Eclipse und haben ein Maven Projekt erstellt vom Typ "maven-archetype-webapp" version 1.0.
12051

Code:
<!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.PostgreSQLDialect</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">123</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>



        <property name="connection_pool_size">1</property>

        <property name="hbm2ddl.auto">create</property>

        <property name="show_sql">true</property>



       <mapping resource="employee.hbm.xml"/>

    </session-factory>
</hibernate-configuration>

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.dirtybit.Employee" table="EMPLOYEE">
    <id name="id">
    <generator class="assigend"></generator>
    </id>

    <property name="firstName"></property>
    <property name="lastName"></property>
</class>

</hibernate-mapping>


Java:
package org.dirtybit.playground;

import org.hibernate.*;
import org.hibernate.cfg.Configuration;

public class StoreData {
    public static void main(String[] args) {
        
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
        
        Transaction tx = session.beginTransaction();
        Employee e = new Employee();
        e.setFirstName("Bob");
        e.setLastName("Baumeister");
        e.setId(101);
        session.save(e);
        tx.commit();
        session.close();
    }
}

Java:
package org.dirtybit.playground;

public class Employee { 
    private int id; 
    private String firstName,lastName; 
    
    protected Employee() { }
    
    public int getId() { 
        return id; 
    } 
    public void setId(int id) { 
        this.id = id; 
    } 
    public String getFirstName() { 
        return firstName; 
    } 
    public void setFirstName(String firstName) { 
        this.firstName = firstName; 
    } 
    public String getLastName() { 
        return lastName; 
    } 
    public void setLastName(String lastName) { 
        this.lastName = lastName; 
    } 
      
      
    }

Juni 07, 2019 1:55:57 NACHM. org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.4.3.Final}
Juni 07, 2019 1:55:58 NACHM. org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Juni 07, 2019 1:55:58 NACHM. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Juni 07, 2019 1:55:58 NACHM. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/postgres]
Juni 07, 2019 1:55:58 NACHM. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, pool_size=1, user=postgres}
Juni 07, 2019 1:55:58 NACHM. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Juni 07, 2019 1:55:58 NACHM. org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Juni 07, 2019 1:55:58 NACHM. org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Exception in thread "main" org.hibernate.MappingException: class org.dirtybit.Employee not found while looking for property: id
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:221)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:513)
at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindSimpleEntityIdentifier(ModelBinder.java:729)
at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindEntityIdentifier(ModelBinder.java:351)
at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindRootEntity(ModelBinder.java:246)
at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindEntityHierarchy(ModelBinder.java:193)
at org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl.processEntityHierarchies(HbmMetadataSourceProcessorImpl.java:144)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:226)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:273)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.dirtybit.playground.StoreData.main(StoreData.java:9)
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.dirtybit.Employee]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:136)
at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:217)
... 14 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.dirtybit.Employee
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:415)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:133)
... 15 more

Eclipse sagt er findet die Klasse Employee nicht während er nach der ID sucht. Ich werde daraus nicht schlau. ich habe die Klassen und xml files nach bestem wissen und gewissen gestaltet.

hoffe auf einen Tipp.
freundliche Grüße,
DirtyBit
 
Passende Stellenanzeigen aus deiner Region:

Neue Themen

Oben