There are a couple of different issues in this: Hibernate does *not* (yet) do mass deletes. Usually we need to load an object up before we delete it, in case it has (1) Lifecycle callbacks (2) toplevel collections (3) cascading deletes (4) references to other deleted objects which need to be nullified before those objects are deleted
I have always intended to someday implement a shortcut where objects that do not have (1), (2), (3), (4) can be deleted en masse. But thats not implemented yet. However, the API is there so that when it does get implemented, everyone's applications will suddenly get faster :) So, that explains why we need to load the objects. On the other hand, I'm not sure why the "useless updates" are occurring. Updates would need to be done if we needed to break any foreign key references to a PriceListItem before deleting it (or a PriceList before deleting *it*) but that doesn't seem to be the case in this case.... i'm confused about that. Im also not sure why the inserts are slow. They shouldn't be. Have you tried disabling batch updates hibernate.use_jdbc_batch=false? Gavin ----- Original Message ----- From: "Andrea Aime" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, October 24, 2002 8:09 PM Subject: [Hibernate] Mass delete and insert performance problems > I have a problem with Hibernate... consider the following mapping > (incomplete, I hope this is the relevant part): > > <class name="it.satanet.ketpl.model.PriceList" table="price_list"> > <id name="id" column="id" type="long"> > <generator class="vm.long"/> > </id> > <property name="date" column="pl_date" type="date"/> > <property name="active" type="boolean" not-null="true"/> > <property name="supplyConditions" column="supply_cond" > type="string" length="1000"/> > <property name="revNumber" column="rev_number" type="integer"/> > <property name="year" column="pl_year" type="short"/> > <many-to-one name="customer" column="customer_id" not-null="true" > class="it.satanet.ketpl.model.Customer"/> > <bag role="items" readonly="true" lazy="true"> > <key type="long" column="pricelist_id"/> > <one-to-many class="it.satanet.ketpl.model.PriceListItem"/> > </bag> > </class> > > <class name="it.satanet.ketpl.model.PriceListItem" > table="pricelist_item"> > <id name="id" column="id" type="long" unsaved-value="null"> > <generator class="vm.long"/> > </id> > <property name="gross" type="big_decimal" length="2"/> > <property name="discount1" type="double"/> > <property name="discount2" type="double"/> > <property name="net" type="big_decimal" length="2"/> > <property name="packing" type="big_decimal" length="2"/> > <property name="note" type="string"/> > <property name="rise" type="double"/> > <property name="novelty" type="boolean" not-null="true"/> > <many-to-one name="article" column="article_id" not-null="true" > class="it.satanet.ketpl.model.Article"/> > <many-to-one name="priceList" column="pricelist_id" not-null="true" > class="it.satanet.ketpl.model.PriceList"/> > </class> > > > When I try the following command to purge the database contents > hibernate goes nuts (this is included in a stateless session bean > method, with container managed transactions): > > s = sf.openSession(); > s.delete("from x in class " + PriceListItem.class); > s.delete("from x in class " + PriceList.class); > s.flush(); > > After the flush I see on the trace a whole lot of infos like > hidrating entity PriceListItem xxx and the a whole lot of > excuting bactch in which the command is an update, and after some > thousands useless updates the entities gets deleted... why oh why > is Hibernate updating the db and trying to load into memory these > object when all I have asked is to delete them? > > Ah, I've noticed that inserting a new PriceList is quite slow (each > price list includes something like 100 items), the batch update > seems to take forever with no CPU consuption at all... I'm running > the following command (into a stateless session bean): > > public void insert(PriceList pl) throws SaveException { > Session s = null; > > try { > s = HibernateUtils.getSession(); > s.save(pl); > List items = pl.getItems(); > if(items != null) { > for(Iterator it = items.iterator(); it.hasNext(); ) { > s.save(it.next()); > } > } > s.flush(); > } catch (Exception e) { > mLog.error("Error while inserting new object:\n" + > HibernateUtils.xmlEncode(pl), e); > mContext.setRollbackOnly(); > throw new SaveException("Object insert failed", e); > } finally { > try {s.close();} catch(Exception e) {e.printStackTrace();} > } > } > > Hibernate is running as a JMX service in JBoss 3.0.2, the db is SAPDB, > I'm using container managed transactions and stateless session bean, > platform is windows 2000 professional... > > > Best regads > Andrea Aime > > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavote > _______________________________________________ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel ------------------------------------------------------- This sf.net email is sponsored by: Influence the future of Java(TM) technology. Join the Java Community Process(SM) (JCP(SM)) program now. http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavote _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel