gpt4 book ai didi

hibernate - Spring 和 Hibernate 配置

转载 作者:行者123 更新时间:2023-12-02 23:41:18 26 4
gpt4 key购买 nike

这是我的 hibernate 配置,但由于某种原因它无法加载我添加到 <property name="hibernateProperties"> 的那些属性并且日志在启动时显示 INFO org.hibernate.cfg.Environment - hibernate.properties not found .

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="url" value="jdbc:postgresql://localhost:5432/testdatabase" />
<property name="username" value="postgres" />
<property name="password" value="password" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="org.test"/>
<property name="hibernateProperties">
<value>
hbm2ddl.auto=create
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
</value>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

</beans>

编辑:完整日志:

    2010-08-29 15:27:15,986 [main] INFO  org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.1.GA
2010-08-29 15:27:15,997 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.2.6
2010-08-29 15:27:16,000 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
2010-08-29 15:27:16,002 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
2010-08-29 15:27:16,005 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2010-08-29 15:27:16,113 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: org.test.TestEntity
2010-08-29 15:27:16,145 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity org.test.TestEntity on table TestEntity
2010-08-29 15:27:16,188 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
2010-08-29 15:27:16,188 [main] INFO org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean - Building new Hibernate SessionFactory
2010-08-29 15:27:16,238 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2010-08-29 15:27:16,663 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: PostgreSQL, version: 9.0beta4
2010-08-29 15:27:16,664 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC3 with SSL (build 603)
2010-08-29 15:27:16,667 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.PostgreSQLDialect
2010-08-29 15:27:16,672 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
2010-08-29 15:27:16,674 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2010-08-29 15:27:16,674 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2010-08-29 15:27:16,674 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2010-08-29 15:27:16,674 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2010-08-29 15:27:16,674 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2010-08-29 15:27:16,675 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2010-08-29 15:27:16,675 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
2010-08-29 15:27:16,675 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2010-08-29 15:27:16,675 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2010-08-29 15:27:16,675 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2010-08-29 15:27:16,676 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2010-08-29 15:27:16,676 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
2010-08-29 15:27:16,676 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2010-08-29 15:27:16,678 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.NoCacheProvider
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2010-08-29 15:27:16,678 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2010-08-29 15:27:16,683 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
2010-08-29 15:27:16,683 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
2010-08-29 15:27:16,683 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2010-08-29 15:27:16,684 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
2010-08-29 15:27:16,684 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
2010-08-29 15:27:16,703 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
2010-08-29 15:27:16,888 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
2010-08-29 15:27:17,096 [main] INFO org.springframework.orm.hibernate3.HibernateTransactionManager - Using DataSource [org.apache.commons.dbcp.BasicDataSource@15b55bc] of Hibernate SessionFactory for HibernateTransactionManager

最佳答案

我认为 hibernateProperties 设置不正确(除非 Spring 有一种我不知道的设置属性的新方法)。通常属性是手动设置的,如下所示:

    <property name="hibernateProperties">
<props>
<prop key="hbm2ddl.auto">create</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>

另一种方法(我更喜欢)是将这些属性粘贴到 hibernate.properties 文件中,然后将该文件放入类路径的根目录中。这可能就是错误消息所指的内容。

关于hibernate - Spring 和 Hibernate 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3594734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com