-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: quickly insert Elements of TreeMap in database
PostPosted: Thu Oct 01, 2009 9:37 am 
Newbie

Joined: Wed Sep 30, 2009 9:03 am
Posts: 3
Hi,

I have the following problem:

there is a class "Consumption" which contains an attribute of type TreeMap:

Code:
public class ConsumptionVo implements Serializable{

    private Map consumptionTable = new TreeMap<Date, Float>();
    private long id;
   ...

}


The Mapping-file is as follows:

Code:
<hibernate-mapping package="domain">
    <class name="ConsumptionVo" table="consumptionelmeter">
        <id name="id">
            <generator class="increment"/>
        </id>
        <map name="consumptionTable" table="consumptionentry" order-by="date asc" lazy="extra" batch-size="20">
            <key column="id" />
            <map-key column="date" type="timestamp"/>
            <element column="consumptionValue" type="float"/>
        </map>
    </class>
</hibernate-mapping>


consumptionTable can contain a lot of values (> 100000).

The problem consists in the fact that batch processing of consumptionTable doesn't work.
By the first call of session.flush () all values of consumptionTable are written in database.
(session by the call of the method is opened ). The insert of entrys of consumptionTable is very long.
For 1000 values the method needs 40 seconds...

Code:
    public ConsumptionVo createManyEntries(ConsumptionVo consumption){
        final ConsumptionVo _consumption = consumption;
        return getHibernateTemplate().execute(new HibernateCallback<ConsumptionVo>() {
            public ConsumptionVo doInHibernate(Session session) throws HibernateException, SQLException {
                Collection<Date> menge = _consumption.getConsumptionTable().keySet();
                Map table = (Map) _consumption.getConsumptionTable();
                int i=1;
                for (Iterator<Date> it = menge.iterator(); it.hasNext();){
                    Date tmp = it.next();
                    consumptionDB.getConsumptionTable().put(tmp, table.get(tmp));
                    table.put(tmp, table.get(tmp));
                    session.saveOrUpdate(_consumption);
                    if ( i%20 == 0 ){
                        session.flush();
                        session.clear();
                    }
                    i++;
                }
                return _consumption;
            }
        });
    }


Is it possible to implement batch processing in this case ? Or is there another solution an object ConsumptionVo with attribute of type TreeMap, that contains a lot of entries, to save time-efficiently in the database?
I would be very grateful for every help and every advice!

user737


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.