0

When my project run on spring 2.5 and hibernate 3.2 it works fine.After updating spring version to 4.1.6 and hibernate version to 3.6.1 i got the following error:

org.hibernate.MappingException: Unknown entity: java.util.ArrayList

My DAO function is :

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

Configuration is :

<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>

My Entity Mapping class:

@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;
}

}`

7
  • May you put the code which cause the error? Commented Apr 3, 2016 at 11:20
  • Show the entity mapping please. Commented Apr 3, 2016 at 11:38
  • can you try replacing you annotatedClasses with <property name="packagesToScan" value="com.cptu.egp.eps.model.table" /> ? Commented Apr 3, 2016 at 12:40
  • getHibernateTemplate().saveOrUpdateAll(collection); this line of code generate the error @BlitheHuang Commented Apr 4, 2016 at 5:32
  • I tried but same error @DeendayalGarg Commented Apr 4, 2016 at 5:32

1 Answer 1

1

According to the source code, there isn't saveOrUpdateAll() method in 4.1.6., and it's also deprecated in spring 3.

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

It looks like you pass the collection to saveOrUpdate(), and hibernate can't find the mapping setting.

Sign up to request clarification or add additional context in comments.

2 Comments

Then what could be the possible alternative?
use foreach and saveOrUpdate(), I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.