0

Basic example used annotations. Configured the mapping class in hibernate.cfg.xml. But I am getting this exception org.hibernate.MappingException: Unknown entity: com.fh.entities.Customer

package com.fh.entities;

@Entity
public class Customer {
    @Id
    private int id;
    private String firstName;
    private String lastName;
    private String mobile;
    private String email;
//setters & getters.
}

In hibernate.cfg.xml:

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
        <property name="connection.username">test</property>
        <property name="connection.password">system</property>
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>
        <mapping class ="com.fh.entities.Customer"></mapping>
    </session-factory>
</hibernate-configuration>

I am getting exception in Eclipse as below:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.fh.entities.Customer
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
smalik
  • 1
  • Please, add the code with Hibernate initialization (`Configuration` etc.). – v.ladynev Jun 08 '18 at 07:50
  • 1
    Possible duplicate of [org.hibernate.MappingException: Unknown entity: annotations.Users](https://stackoverflow.com/questions/23214454/org-hibernate-mappingexception-unknown-entity-annotations-users) – Rcordoval Jun 08 '18 at 07:59
  • Is your table created or Hibernate is going to create? – ajay tomar Jun 08 '18 at 08:26

1 Answers1

0

You can use @Table(name = "Customer", catalog = "") on your entity class and create the table in database before starting the application. Update: Use this as below, Create is not idle for live applications.

 <property name="hbm2ddl.auto">update</property>
ajay tomar
  • 384
  • 1
  • 16