0

I am currently working on a web project where i am using hibernate.cfg.xml. Now i a planning to move all entity model classes to a separate jar and then refer the entites from the external jar. Also I am not using Entity Manager anywhere. Am using SessionFactory so have only included hibernate.cfg.xml file.

Below Hibernate.cfg.file has been placed in WEB-INF->classes folder

<?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">org.sqlite.JDBC</property>

        <property name="connection.url">jdbc:sqlite:C:\workspace\gsepHelpdeskDB.sqlite</property>
        <property name="connection.username"></property>
        <property name="connection.password"/>


            <property name="hibernate.connection.provider_class">
                        org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
        <property name="hibernate.c3p0.min_size">1</property>
        <property name="hibernate.c3p0.max_size">50</property>
        <property name="hibernate.c3p0.timeout">120</property>
        <property name="hibernate.c3p0.max_statements">10</property>

        <!-- SQL dialect -->
        <property name="dialect">com.enigmabridge.hibernate.dialect.SQLiteDialect</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</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> -->

        <!-- Do not Drop, only update the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

            <!-- <mapping resource="org.hibernateDemo.dto.UserDetails.hbm.xml"/> -->      
    <mapping class="com.daimler.gsep.Tool"/>
    <mapping class="com.daimler.gsep.RequestorInfo"/>



    </session-factory>

</hibernate-configuration>

The entity classes mentioned in mapping tag of hibernate config file are actually placed in a jar named projectAutomationPOJOs.jar. And I have placed the jar in the lib folder. When I am running the application, then I am getting error like "Tool is not mapped".

Shivani Bhansali
  • 109
  • 1
  • 12
  • Hi @BillyFrost have edited my post and added code. – Shivani Bhansali Oct 17 '18 at 08:36
  • no creating a Session factory and then trying to fetch data by hql "FROM Tool" – Shivani Bhansali Oct 17 '18 at 09:39
  • i have my Tool.java entity class in a jar file. It is an external entity. Have added the jar to lib folder but hibernate is not able to find it. – Shivani Bhansali Oct 17 '18 at 09:41
  • 1
    Probably your projectAutomationPOJOs.jar is not on the classpath or `Tool` class is not mapped entity - you have to have at least `@Entity` annotation on it. – Antoniossss Oct 17 '18 at 10:52
  • The tool class has @Entity annotation on it. projectAutomationPOJOs.jar is added on classpath. Do i need to specify any extra configuration in hibernate.cfg.xml to let it know that the entities to scanned are in external jar? – Shivani Bhansali Oct 17 '18 at 12:10
  • No, just these 2 requirements have to be met (so at least 1 of them are not). Is it standalone application or some sort of Spring boot maybe? It is possible that you got isolated class loaders (spring boot would have) and from the context classloader of configuration reader, that class is not accessible. But to be honest, that would result in class not found exectpion i think. Also double check if you are using @Entity from javax package. – Antoniossss Oct 17 '18 at 12:27
  • Possible duplicate of [Hibernate throws strange error: Class is not mapped](https://stackoverflow.com/questions/8524767/hibernate-throws-strange-error-class-is-not-mapped) – Antoniossss Oct 17 '18 at 12:31
  • Yess. @Entity was org.hibernate. Used javax.persistence. Issue resolved. Thank you :) – Shivani Bhansali Oct 17 '18 at 13:09

0 Answers0