答1:
两种方法是相同的。默认情况下,hibernate从中读取配置
classpath:hibernate.cfg.xml以进行构建
SessionFactory。
LocalSessionFactoryBean只允许你设置hibernate配置里面
applicationContext.xml,而不是
hibernate.cfg.xml。
如果在两个文件中都指定了相同的属性,则取决于该属性,它将具有上瘾的效果,或者中指定的属性
applicationContext.xml将具有更高的优先级,因此
hibernate.cfg.xml将忽略其中的那些值 。
对于方法1,
annotatedClasses并且
hibernateProperties应该与在相应的值的成瘾效果
hibernate.cfg.xml。DBCP
dataSouruce中的
applicationContext.xml应引起相关属性
hibernate.cfg.xml被忽略。
答案2:
对于方法2,如果未指定的任何属性
LocalSessionFactoryBean,则所有的hibernate配置均由指定
hibernate.cfg.xml。如果在没有配置连接池
hibernate.cfg.xml,Hibernate的连接池算法默认情况下使用,这是相当简陋,不打算用于生产系统,甚至性能测试。



