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 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算