Hibernate: Unable to load class declared in Hibernate configuration entry

后端 未结 10 1288
野趣味
野趣味 2021-01-21 01:03

I am completely new in Hibernate and got such an stacktrace:

hql> from TracksEntity 
[2014-04-26 21:13:45] org.hibernate.MappingException: Unable to load clas         


        
相关标签:
10条回答
  • 2021-01-21 01:04

    My mistake was a camel case problem. I had an embedded entity "IndexPK" and wrote "IndexPk" in the mapping file. I compared it ~20 times.... till I figured this out.

    0 讨论(0)
  • 2021-01-21 01:08

    I had a similar problem when the mapping file wouldn´t load correctly. The answer to this problem seems to be that we need to use the correct import statements in our Model classes.

    Changing the import to import javax.persistence.Entity instead of using the one from hibernate package ( ie org.hibernate.annotations.Entity), fixed the issue in my case.

    This issue is a real pain , and I spent more than 1/2 day looking at all corners, when a simple import fixed the issue.

    Hope this helps.

    0 讨论(0)
  • 2021-01-21 01:10

    Sounds quite silly but i was putting my entity Class in a package which is not the same i put in the mapping.. and hibernate of course could not find it... just for reference.. maybe a recheck can solve your problem best regards.

    0 讨论(0)
  • 2021-01-21 01:12

    I was having the same issue, After adding this dependency it's resolved.

        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    
    0 讨论(0)
  • 2021-01-21 01:14
    write in this pattern
    
     <session-factory>
    
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dairy
        </property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.current_session_context_class">thread</property>
    
        <!-- MAPPING -->
        <!-- <mapping class="com.om.model.Test" /> -->
        <mapping class="com.om.model.RateCalculationBean" />
    
    </session-factory>
    

    and also no need to mention scema

    0 讨论(0)
  • 2021-01-21 01:15

    To resolve this issue add maven spring-boot dependency

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
       <exclusions>
           <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-logging</artifactId>
           </exclusion>
       </exclusions>
    
    0 讨论(0)
提交回复
热议问题