Spring Cfg + Hibernate Cfg和Anotations

时间:2015-09-21 15:23:47

标签: java spring hibernate hql

我想用HQL进行测试,但映射表带有Annotations。 Hibernate配置文件位于/WEB-INF/spring-config-ws.xml :::>  

<!-- Activate transaction declarations with annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>

<!-- Property files application uses -->
<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>
        </list>
    </property>
</bean>

<!-- JNDI DataSource -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="${dataSource.jndiName}" />
    <property name="lookupOnStartup" value="false"/>
    <property name="cache" value="true"/>
    <property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>

<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
    <property name="packagesToScan">
        <list>
            <value>es.sergas.rprof.profesional.domain</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.default_schema">${hibernate.default_schema}</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
        </props>
    </property>
</bean>

<!-- Transaction manager for Hibernate SessionFactory -->
<bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

当我运行列表时,我发现你没有找到hibernate cfg: 找不到hibernate.cfg.xml

我只想列出带注释的映射类,但是HQL

我觉得我的英语水平很低。谢谢

1 个答案:

答案 0 :(得分:0)

确保hibernate.cfg.xml位于src/main/resources内,如果文件不在那里,则需要指定正确的位置,因此请将其放在此文件夹中以解决您的问题。

  

请注意,我们不必明确提及映射或配置或属性   文件,因为Hibernate运行时查找默认文件名,例如hibernate。   cfg.xml或hibernate.properties,在类路径中加载它们。如果我们有非默认   名称,请确保将其作为类似参数的配置传递(&#34; my-hibcfg。   例如,xml&#34;)。

相关问题