Spring Hibernate integration of two ways

Unusual question "com.ssh.entry.Product:: Unknown entity org.hibernate.MappingException" appears in the use of spring annotation integrate hibernate.

Finally found the problem, to sum up

1.spring integration hibernate, replace * .hbm.xml profile
  configuration file in applicationContext.xml

<!-- 创建sessionFactory -->
         <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
                 <property name="dataSource" ref="dataSource"></property>
                <!-- 使用统配符 配置hibernate hbm配置文件   -->
                <property name="mappingLocations">
                    <value>classpath*:com/jxc/entity/*.hbm.xml</value>
                </property>
                  
                <!--hibernate属性配置 -->
                <property name="hibernateProperties">
                    <props>
                        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                        <prop key="hibernate.hbm2ddl.auto">update</prop>
                        <prop key="hibernate.show_sql">true</prop>
                        <prop key="hibernate.format_sql">true</prop>
                    </props>
                </property>
        </bean>

The above code is used to compare the previous

spring integrate hibernate, using the annotation style
    configuration file in the way applicationContext.xml

<! - Hibernate configuration the SessionFactory -> 
    <the bean ID = "the sessionFactory" class = "org.springframework.orm.hibernate5.LocalSessionFactoryBean"> 
        <! - filling connection pool -> 
        <Property name = "the dataSource" REF = "the dataSource" /> 
        <-! scanned and loaded annotated entity class -> 
        <property name = "packagesToScan" value = "com.kaspar.product.model" /> 
        <-! Hibernate configuration properties - > 
        <Property name = "hibernateProperties"> 
            <props> 
                <prop Key = "the hibernate.show_sql"> to true </ prop> <-! show whether SQL -> 
                <prop Key = "Hibernate.format_sql "> to true </ prop> <-! bottom sql statement output format ->
                <prop key = "hibernate.hbm2ddl.auto"> update </ prop> <-! whether to automatically create a table structure -> 
                <prop Key = "hibernate.dialect"> org.hibernate.dialect.MySQLDialect </ prop> 
            </ The props> 
        </ Property> 
        
    </ the bean>

Wherein the upper section or alternatively as:

<! - common parameters configuration database -> 
<Property name = "packagesToScan"> 
            <List> 
                <value> com.kaspar.product.model </ value> 
           </ List> 
</ Property>

This is the second way to use annotations. There are only two ways to introduce differences in class when mapping files or annotations.

The first time consolidation annotation appears: "org.hibernate.MappingException: Unknown entity: com.ssh.entry.Product"

Here introducing path, just enter the package name on it.

Guess you like

Origin www.cnblogs.com/kaspar/p/12016618.html