代码之家  ›  专栏  ›  技术社区  ›  JavaKB

持续休眠缓存使用率开始

  •  0
  • JavaKB  · 技术社区  · 14 年前

    我有缓存使用问题,我有以下映射。无论出于何种原因,ST_CD被两次映射到两个不同的属性。休眠正在抛出

    org.hibernate.MappingException: Repeated column in mapping for entity: my.package.State column: ST_CD (should be mapped with insert="false" update="false")
    

    我的缓存使用是“只读”的,所以我想插入和更新总是错误的;为什么我要明确地说insert=“false”update=“false)?

    <class mutable="false" name="my.package.State" table="STATE_TABLE">
        <cache usage="read-only" />
        <id name="id" column="ST_ID" type="long" />
        <property name="code" type="string" column="ST_CD" />
        <property name="stateAbbreviationCode" type="string" column="ST_CD"/>
        <!- Other properites -->
    </class>
    
    2 回复  |  直到 14 年前
        1
  •  0
  •   ManuPK    14 年前

    当您在hibernate中创建实体时, 应该可以使用普通的bean了。无论是否缓存,都无法通过多个属性更新数据库 。因此,您需要在其中一个属性上使用'insert=“false”update=“false'。

        2
  •  0
  •   awsbz77    14 年前

    它在映射中的问题,

    最后两个属性中使用了相同的列(ST_CD)

    <property name="code" type="string" column="ST_CD" />    
    <property name="stateAbbreviationCode" type="string" column="ST_CD"/> 
    

    正确的映射是这样的,

    <property name="code" type="string" column="ST_CD" />    
    <property name="stateAbbreviationCode" type="string" column="ST_ABBR_CD"/>