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

  • SEARCH
  • Home
  • 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 4076744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:27:51+00:00 2026-05-20T17:27:51+00:00

I am using Hibernate in Spring MVC 3.05 and an Oracle database. I have

  • 0

I am using Hibernate in Spring MVC 3.05 and an Oracle database.

I have a transaction in which I insert a new record into two tables: User and Registration.

Registration contains a UserId (meaning a user may have many registrations).

When I commit the transaction, I can query my database and see that the new rows were successfully inserted.

The problem
After the transaction commits successfully, I redirect the user to a confirmation page, where I would like to show some information about the registration that was just inserted. On the confirmation page, I do a Hibernate query by userId to get the User that was just inserted. I then use the following properties to populate my model:

  • User.getName()
  • User.getEmail()
  • User.getBlah()
  • User.getReigstrations().iterator.next()

The one in bold throws an exception “NoSuchElementException” because there are no items in the set. There should be one Registration in the set. If I close the browser, start a new one, and direct myself back to the same link that threw the exception, IT WORKS! There is a Registration in the set.

My guess is that it’s not reloading related table objects when I query for my User, but is either pulling from cache or assuming that nothing more had been added since the User was saved. Does anyone know of a way to force Hibernate to reload this data?

Unfortunately I can’t just get a Registration by UserId because it maps UserId to the entire User object (via object generation because User is a foreign key).

Hope this makes sense. Any help is appreciated. I am open to a different approach to accomplishing this as well. Thanks!

  • 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-20T17:27:51+00:00Added an answer on May 20, 2026 at 5:27 pm

    It’s hard to diagnose the exact problem because you don’t say when you close sessions, and in which session/transaction you get your User. But I guess the problem comes from the fact that you don’t maintain the two sides of the relationship when inserting a new registration.

    You should set the user in the registration, and add the registration to the list of registrations of the user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to spring mvc, roo and hibernate. I'm using Oracle XE 10g database.
I have an application which are using Hibernate / Spring and Spring MVC, but
I have Spring MVC project. I am using HSQL database and Hibernate. I have
I'm working on a Spring MVC project in which I'm using Hibernate Validator to
I have the following HQL in Hibernate using Spring MVC. List<Colour>list=session.createQuery(from Colour order by
I have java application with web interface (Spring MVC) using Hibernate. I have quite
I have some web-project (Spring MVC + Hibernate). For hibernate objects I am using
I have a spring mvc application that I am using Hibernate with. I am
I have Roo-generated Spring MVC application connected to PostgreSQL using Hibernate. I am trying
I am creating a Spring MVC Hibernate application using MySQL. Where should I save

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.