Results 1 to 2 of 2

Thread: HibernateTemplate: unnecessary SELECT statement

  1. #1
    Join Date
    Apr 2008
    Posts
    15

    Default HibernateTemplate: unnecessary SELECT statement

    My DAO uses an HibernateTemplate to access the DB. The following method adds multiple Transactions:

    Code:
    public void saveTransactions(Collection<Transaction> transactions) {
    		getHibernateTemplate().saveOrUpdateAll(transactions);
    	}
    These are the queries that Hibernate generates for a Collection of three Transactions:

    Code:
    Hibernate: insert into TRANSACTIONS (PROVIDERID, MAC, EVENTID, PRICE, TIMESTAMP, SELECTIONID, TEXTSTRING, EXPORTEDFORPOSTPROCESSING, EXPORTEDFORBILLING, TRANSACTIONID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, null)
    Hibernate: call identity()
    Hibernate: insert into TRANSACTIONS (PROVIDERID, MAC, EVENTID, PRICE, TIMESTAMP, SELECTIONID, TEXTSTRING, EXPORTEDFORPOSTPROCESSING, EXPORTEDFORBILLING, TRANSACTIONID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, null)
    Hibernate: call identity()
    Hibernate: insert into TRANSACTIONS (PROVIDERID, MAC, EVENTID, PRICE, TIMESTAMP, SELECTIONID, TEXTSTRING, EXPORTEDFORPOSTPROCESSING, EXPORTEDFORBILLING, TRANSACTIONID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, null)
    Hibernate: call identity()
    Hibernate: select transactio0_.TRANSACTIONID as TRANSACT1_0_, transactio0_.PROVIDERID as PROVIDERID0_, transactio0_.MAC as MAC0_, transactio0_.EVENTID as EVENTID0_, transactio0_.PRICE as PRICE0_, transactio0_.TIMESTAMP as TIMESTAMP0_, transactio0_.SELECTIONID as SELECTIO7_0_, transactio0_.TEXTSTRING as TEXTSTRING0_, transactio0_.EXPORTEDFORPOSTPROCESSING as EXPORTED9_0_, transactio0_.EXPORTEDFORBILLING as EXPORTE10_0_ from TRANSACTIONS transactio0_
    I'm assuming Hibernates generates the SELECT statement to keep its corresponding POJO's up-to-date. If I'm no longer interested in the Transaction objects after they are INSERTed into the DB, there's no point in performing a SELECT to update them. How can I make it clear to Hibernate that it should not perform the SELECT statement? Thanks!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    You cannot.

    After insertion hibernate publishes back the generated id's to the objects. There is no way (I know of) to disable that.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •