Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4344288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:52:32+00:00 2026-05-21T11:52:32+00:00

Long story below short question: How can I get Spring’s NamedParameterJDBCTemplate join Hibernate’s session?

  • 0

Long story below short question: How can I get Spring’s NamedParameterJDBCTemplate join Hibernate’s session?
We’ve an application using Spring and Hibernate, our whole datalayer is with Hibernate. But now there is a use case where we have a parent object for which the whole hibernate logic is in place. The parent object has many (> 4000) details, which we do want to insert using Spring’s jdbctemplate, all in one transaction (instead of using hibernate). The parent object is saved, the Parent’s id (which is an oracle sequence) is set, and readable via the object. We only have to commit in order to permanently store it.
The transaction boundary is set on a method which also fires the 4000+ jdbctemplate inserts of the details.
The details, being details, do need a reference to the parent object which is the parent’s id, available at the time the 4000+ insertions are being executed. However on the insert of the first detail, I get a

integrity constraint (FK_008) violated - parent key not found

I think I do understand that, as the jdbctemplate is probably using another session and therefor another transaction. I tried setting a propegation:required transaction attribute on the method doing the 4000+ inserts, expecting that the join of the transaction would be sufficient to be able to read the new uncommitted parent id, but that was obvious not enough.
I’m hoping that I can somehow wire the hibernate session into spring’s jdbctemplate but so far I haven’t been able to do so. The SpringJDBC takes the dataSource as argument, the jtatransaction manager takes the Hibernate SessionFactory, and so far I’ve the feeling that east is east and west and never the twain shall meet. Are there other ways, to make Spring’s jdbctemplate participating in Hibernate’s Session? (except of coursing committing the parent’s insert so the parent-id is available the jdbctemplate).

HibernateSessionFactory is an org.springframework.orm.hibernate3.LocalSessionFactoryBean
with the dataSource as one of the arguments.

TransactionManager is the org.springframework.orm.hibernate3.HibernateTransactionManager which gets the sessionFactory as the argument.

The NamedParameterJDBCTemplate is created in the setter of the sqlInserter:

public void setDataSource(DataSource dataSource) {
    jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

Hopefully somebody can help me out here.

Cheers,
Jeroen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:52:32+00:00Added an answer on May 21, 2026 at 11:52 am

    You should do your 4000+ insertions via Hibernate via batch updates technique. :

    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    
    ScrollableResults customers = session.getNamedQuery("GetCustomers")
        .setCacheMode(CacheMode.IGNORE)
        .scroll(ScrollMode.FORWARD_ONLY);
    int count=0;
    while ( customers.next() ) {
        Customer customer = (Customer) customers.get(0);
        customer.updateStuff(...);
        if ( ++count % 20 == 0 ) {
            //flush a batch of updates and release memory:
            session.flush();
            session.clear();
        }
    }
    
    tx.commit();
    session.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short, the database I'm using needs to get looked at. Until that
Long story short, I have an ASP.NET application I'm trying to debug and at
Long story short, client's hosting is using php 5.2.5 and i desperately need to
Well long story short, my application needs to connect to the database in the
Long story short, the snippets below is about converting the texted month to numbered
Long story short, I have a struct (see below) that contains exactly one field:
Ok - long story short. Have an e-comm site hosted on Windows VPS using
To cut a long story short I have a section of my application that
So long story short, for ages, ive been using some CSS reset on my
Long story short, we found files promoting prescription drugs on our server that we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.