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 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

We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data
I'm using Hibernate with Spring in my application. I have been consistently using detached
Hey I am developing an desktop application using Spring and Hibernate, and I have
I'm using Hibernate Validator in an application with EJB and Spring MVC. I'm using
I am using Spring MVC and Hibernate. I want to use the OpenSessionInViewFilter to
I am using Hibernate with my Spring MVC project. Lets say my model has
I am using the Spring MVC framework with Hibernate. All of my controllers are
NOTE: I am using a J2EE Spring MVC + Hibernate with both using annotations
I´m using JPA Hibernate and Spring MVC. I haved implemented repository pattern. I get
I am using hibernate annotations with spring MVC. Now i always create table using

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.