weixin_42357451 2010-02-08 15:27
浏览 160
已采纳

JPA注释问题

这个问题弄了一个上午了。。。 :cry:

是这样,我在使用JPA注释的时候Column总是无法映射到正确的列名上,比如Entity片段

[code="java"]
@Entity
@Table(name = "ktmap", schema = "ge")
。。。
@Column(name="min_lv")
public Integer getMinLv() {
return minLv;
}
[/code]
hibernate打出来的SQL始终是minLv而不是min_lv。。。

无语了,请哪位帮忙看一下吧。
这个是applicationContext.xml
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    <property name="hibernateProperties">
        <value>
            hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
            hibernate.query.substitutions=true 'Y', false 'N'
            hibernate.cache.use_second_level_cache=true
            hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
            hibernate.cache.use_query_cache=true
            hibernate.show_sql=true
            hibernate.format_sql=true
            hibernate.jdbc.batch_size=25
            hibernate.jdbc.fetch_size=50 
            hibernate.hbm2ddl.auto=none     
            net.sf.ehcache.configurationResourceName=classpath:ehcache.xml
        </value>
    </property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/> 
    <property name="maxActive" value="200"/>
    <property name="initialSize" value="30"/>        
    <property name="maxIdle" value="30"/>
    <property name="minIdle" value="20"/>
    <property name="maxWait" value="1000"/>
    <property name="defaultAutoCommit" value="true"/>
    <property name="removeAbandoned" value="true"/>
    <property name="removeAbandonedTimeout" value="60"/>
    <property name="logAbandoned" value="false"/>
    <property name="validationQuery" value="SELECT 1"/>
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="false" />
    <property name="testWhileIdle" value="true"/>
    <property name="timeBetweenEvictionRunsMillis" value="3600000"/>
    <property name="minEvictableIdleTimeMillis" value="18000000"/>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>             
        </list>
    </property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
    <property name="sessionFactory" ref="sessionFactory"/>  
    <property name="dataSource" ref="dataSource"/>  
</bean>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">  
    <property name="transactionInterceptor" ref="transactionInterceptor"/>  
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">  
    <property name="transactionManager" ref="transactionManager"/>  
    <property name="transactionAttributeSource">  
        <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>  
    </property>  
</bean>
<bean id="beanNameAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
    <property name="beanNames">  
        <list><value>*Service</value></list>  
    </property>    
    <property name="interceptorNames">  
        <list><value>transactionInterceptor</value></list>  
    </property>  
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />


[/code]

其中Datasource使用了propertyConfigurer从jdbc中获得的,这个是没有问题的。
也就是说如果我在数据库中加入minLv列,是可以取到数据的。hibernate.cfg.xml里面只有mapping-class没有其他的东西。

  • 写回答

4条回答 默认 最新

  • yonglin4605 2010-02-08 16:48
    关注

    晕,那你试一试写到属性上面去啊
    PS:同名的就没必要写@Column注解了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器