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