关于Spring中properties中prop中key值的一个小疑问

在spring中会遇到类似于如下的配置,其中的property 中那么的设置我是明白的是对应类中的setXXX的对应关系,但是当setJpaProperties时,我就不是很明白其中的prop的key值,如下为什么是key="hibernate.dialect"而不是其他的key="dialect"这里的key值的确定格式要根据什么来确定呢?

<property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">${db.hibernate.dialect}</prop> 
            <prop key="hibernate.max_fetch_depth">${db.hibernate.max_fetch_depth}</prop> 
            <prop key="hibernate.jdbc.fetch_size">${db.hibernate.jdbc.fetch_size}</prop> 
            <prop key="hibernate.jdbc.batch_size">${db.hibernate.jdbc.batch_size}</prop> 
            <prop key="hibernate.show_sql">${db.hibernate.show_sql}</prop>
            <!-- 配置显示sql语句 -->
            <prop key="hibernate.show_sql">true</prop>
            <!-- 让输出的sql语句格式化 -->
            <prop key="format_sql">true</prop>
            <!--  <prop key="hibernate.hbm2ddl.auto">update</prop> -->
        </props>
    </property>

里面的key必须要用hibernate.名字来修饰,这是内定的。

1.、首先要明白配置文件key肯定是为了取value的,一般情况是可以随意定的,先搞明白代码中有没有调用key取value,看看怎么取的,你就明白了。
2、 为代码规范 都是 key和value后半部分一致。

这里补下Spring管理entityManagerFactory的bean
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

    <property name="dataSource" ref="dataSource"></property>
    <property name="persistenceUnitName" value="default"></property>
    <property name="packagesToScan" value="com.qdm"></property>

    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></bean>
    </property>

    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">${db.hibernate.dialect}</prop> 
            <prop key="hibernate.max_fetch_depth">${db.hibernate.max_fetch_depth}</prop> 
            <prop key="hibernate.jdbc.fetch_size">${db.hibernate.jdbc.fetch_size}</prop> 
            <prop key="hibernate.jdbc.batch_size">${db.hibernate.jdbc.batch_size}</prop> 
            <prop key="hibernate.show_sql">${db.hibernate.show_sql}</prop>
            <!-- 配置显示sql语句 -->
            <prop key="hibernate.show_sql">true</prop>
            <!-- 让输出的sql语句格式化 -->
            <prop key="format_sql">true</prop>
            <!--  <prop key="hibernate.hbm2ddl.auto">update</prop> -->
        </props>
    </property>
</bean>

package org.hibernate.cfg;

/**

  • @author Steve Ebersole
    /
    public interface AvailableSettings {
    /
    *

    • Defines a name for the {@link org.hibernate.SessionFactory}. Useful both to
      • allow serialization and deserialization to work across different jvms
    • optionally allow the SessionFactory to be bound into JNDI
    * @see #SESSION_FACTORY_NAME_IS_JNDI */ public static final String SESSION_FACTORY_NAME = "hibernate.session_factory_name";

    /**

    • Does the value defined by {@link #SESSION_FACTORY_NAME} represent a {@literal JNDI} namespace into which
    • the {@link org.hibernate.SessionFactory} should be bound? */ public static final String SESSION_FACTORY_NAME_IS_JNDI = "hibernate.session_factory_name_is_jndi";

    /**

    • Names the {@link org.hibernate.service.jdbc.connections.spi.ConnectionProvider} to use for obtaining
    • JDBC connections. Can either reference an instance of
    • {@link org.hibernate.service.jdbc.connections.spi.ConnectionProvider} or a {@link Class} or {@link String}
    • reference to the {@link org.hibernate.service.jdbc.connections.spi.ConnectionProvider} implementation
    • class. */ public static final String CONNECTION_PROVIDER ="hibernate.connection.provider_class";

    /**

    • Names the {@literal JDBC} driver class */ public static final String DRIVER ="hibernate.connection.driver_class";

    /**

    • Names the {@literal JDBC} connection url. */ public static final String URL ="hibernate.connection.url";

    /**

    • Names the connection user. This might mean one of 2 things in out-of-the-box Hibernate
    • {@link org.hibernate.service.jdbc.connections.spi.ConnectionProvider}:
      • The username used to pass along to creating the JDBC connection
      • The username used to obtain a JDBC connection from a data source
      */ public static final String USER ="hibernate.connection.username";

      /**

      • Names the connection password. See usage discussion on {@link #USER} */ public static final String PASS ="hibernate.connection.password";

      /**

      • Names the {@literal JDBC} transaction isolation level */ public static final String ISOLATION ="hibernate.connection.isolation";

      /**

      • Names the {@literal JDBC} autocommit mode */ public static final String AUTOCOMMIT ="hibernate.connection.autocommit";

      /**

      • Maximum number of inactive connections for the built-in Hibernate connection pool. */ public static final String POOL_SIZE ="hibernate.connection.pool_size";

      /**

      • Names a {@link javax.sql.DataSource}. Can either reference a {@link javax.sql.DataSource} instance or
      • a {@literal JNDI} name under which to locate the {@link javax.sql.DataSource}. */ public static final String DATASOURCE ="hibernate.connection.datasource";

      这是spring为hibernate的一个规范,而hibernate.dialect中的hibernate是一个标识。

      使用crtl+h 在*.jar中查找对应的key,应该能找到哪里调用了。