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 6580739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:03:54+00:00 2026-05-25T16:03:54+00:00

I have a Struts 1.3 and Hibernate 3.1 application that uses an open-session-in-view pattern

  • 0

I have a Struts 1.3 and Hibernate 3.1 application that uses an open-session-in-view pattern for maintaining hibernate transactions. After I do a session.save() on an object its identifier is being set in the object, however after I pass the object to a new action class all of the properties that are managed by hibernate, like the object’s identifier are being set to null.

The client isn’t using Spring so I had to write my own request filter implementation of the pattern which looks like:

//get a transaction from JTA
transaction = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");

        transaction.begin();

        // Call the next filter (continue request processing)
chain.doFilter(request, response);

// Commit and cleanup
log.finer("Committing the database transaction");
transaction.commit();

My SaveActionClass calls a service layer to persist the object and its associated list (where I’m controlling the session) looks like this:

this.saveAddresses(vendor); //saves a persistant set to the database via dao

this.saveExpCodes(vendor, expCodes); //saves a persistant set to the database  via dao

this.savePhoneNumbers(vendor); //saves a persistant set to the database  via dao

vendor.save(); //saves the vendor object to the database via dao

session.flush();  

session.refresh(vendor);

After the vendor object is persisted the vendor object and all of its children objects have valid identifiers. The vendor object is then added to a DynActionForm property and then forwarded to a ViewActionClass:

dynaActionForm.set(VENDOR_PROPERTY_NAME, vendor);

return actionMapping.findForward(target); //viewvendor

Then in the ViewActionClass when I get the vendor property all the identifiers are set to null:

Vendor vendor = (Vendor)dynaActionForm.get(VENDOR_PROPERTY_NAME); //vendorid is now null

Why is the persistent object losing its identifiers when its being passed from one action class to another via property in dynActionForm?

  • 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-25T16:03:55+00:00Added an answer on May 25, 2026 at 4:03 pm

    The trick here was the placement of the session.refresh() in the getVendor service method:

    public Vendor getVendor(Vendor vendor, Boolean refresh) {
        Session session = HibernateUtil.getSession();
    
        session.setFlushMode(FlushMode.MANUAL);
    
            //refreshing the session here before the get call gave me the would still set some properties to null
            /*
            if(refresh.booleanValue()){
            session.refresh(vendor);
        }
        */
    
        vendor = vendor.get();
    
            //however putting the refresh here, after the get() call populated the vendor object properly
        if(refresh.booleanValue()){
            session.refresh(vendor);
        }
            ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struts application that uses Hibernate to access a MYSQL DB. I
I have a JSP struts application that uses Spring to integrate with the services/dao/database.
I have a web application that using Struts + Spring + Hibernate . In
We have a web application which uses Struts 2, Spring and Hibernate. Currently a
I am working in a struts-hibernate application. I have seen a error on 3rd
I am developing a web application using Struts 2.1.2 and Hibernate 3.2.6.GA. I have
We have a Struts 2 web application that's used by pretty much every employee
I have legacy application using struts & ejb2.0 , hibernate v3.0 running on JBoss
My project uses struts,hibernate and spring,oracle db ,WebLogic server. I have a transaction inserting
I am developing an application in struts 2 and hibernate 3. I have 3

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.