org.springframework.orm.hibernate3.HibernateSystemException:未知实体:java.util.ArrayList

时间:2016-04-03 10:58:35

标签: java spring hibernate arraylist

当我的项目在spring 2.5和hibernate 3.2上运行时,它工作正常。在将spring版本更新到4.1.6并将hibernate版本更新到3.6.1后,我收到以下错误:

  

org.hibernate.MappingException:未知实体:java.util.ArrayList

我的DAO功能是:

public void updateAll(Collection<EntityType> collection) {
    try {
    getHibernateTemplate().saveOrUpdateAll(collection);
    } catch (Exception e) {
        logger.error("updateAll :"+e);
    }
}

配置是:

<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory">
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
    <property name="annotatedClasses">
        <list>
            <value>com.cptu.egp.eps.model.table.TblCountryMaster</value>
             </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
            <prop key="current_session_context_class">thread</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.connection.autocommit">true</prop>
            <prop key="hibernate.cache.provider_class">                  net.sf.ehcache.hibernate.EhCacheProvider</prop>
            <prop key="hibernate.cache.provider_class"> net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
            <prop key="hibernate.max_fetch_depth">5</prop>
            <prop key="hibernate.default_batch_fetch_size">16</prop>
            <prop key="hibernate.jdbc.batch_size">25</prop>
            <prop key="hibernate.jdbc.fetch_size">8</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.connection.release_mode">after_statement</prop>
        </props>
    </property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" />

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

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

我的实体映射类:

@Entity
@Table(name = "tbl_TenderEstCost", schema = "dbo")
public class TblTenderEstCost implements java.io.Serializable {

private int estCostLotId;
private TblTenderMaster tblTenderMaster;

public TblTenderEstCost() {
}

public TblTenderEstCost(int estCostLotId, TblTenderMaster tblTenderMaster) {
    this.estCostLotId = estCostLotId;
    this.tblTenderMaster = tblTenderMaster;
}

@Id
 @GeneratedValue(generator = "TblTenderEstCostSequence", strategy = GenerationType.IDENTITY)
@SequenceGenerator(name = "TblTenderEstCostSequence", sequenceName = "tblTenderEstCost_sequence", allocationSize = 25)

@Column(name = "estCostLotId", unique = true, nullable = false)
public int getEstCostLotId() {
    return this.estCostLotId;
}

public void setEstCostLotId(int estCostLotId) {
    this.estCostLotId = estCostLotId;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tenderId", nullable = false)
public TblTenderMaster getTblTenderMaster() {
    return tblTenderMaster;
}

public void setTblTenderMaster(TblTenderMaster tblTenderMaster) {
    this.tblTenderMaster = tblTenderMaster;
}

}`

1 个答案:

答案 0 :(得分:1)

根据源代码,4.1.6中没有saveOrUpdateAll()方法,并且在春季3也不推荐使用。

http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-orm/4.1.6.RELEASE/org/springframework/orm/hibernate4/HibernateTemplate.java#HibernateTemplate

看起来你将集合传递给saveOrUpdate(),而hibernate找不到映射设置。