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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:30:39+00:00 2026-05-27T06:30:39+00:00

Today I came across one situation, here it is. I have a db object

  • 0

Today I came across one situation, here it is.

I have a db object to persist. I use SampleBean.add method. Inside that method, I’m getting primary key from a sequence, setting it to db object’s id property and persisting it to db (using PreparedStatement). But I could not get the db object’s id property (it comes as 0, even though it got set in persisting method) from the method I’am calling that bean method.

Please clarify me this.

DB Object

public class LogRow implements Serializable {
     public long cardLogId;
     public String data;
}

Persist method

public void insertLogRow(LogRow logRow) {
        Connection con = null;
        PreparedStatement ps = null;        
        try {
            String insertSql = LogRow.INSERT_LOG;
            con = global.getConnection();
            if (logger.isEnabled(IMessage.DEBUG1)) {
                logger.println(IMessage.DEBUG1, CLASS_NAME + "insertLogRow():: insertSql " + insertSql);
            }
            ps = con.prepareStatement(insertSql);
            logRow.setLogId(seq.getNextVal());
            ps.executeUpdate(); 
        } catch (SQLException sqe) {          
            logger.println("insertLogRow():: SQLException occurred");
            throw new ProcessingErrorException(sqe.getMessage());
        } 
}

I am able to see the persisted id value here in persist method.

Calling method

RemoteLookup.getSampleBean().insertLogRow(logRow);
log.println("log id " + logRow.logId());

This calling method prints 0

  • 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-27T06:30:40+00:00Added an answer on May 27, 2026 at 6:30 am

    This is not an Answer:
    Since the question is very difficult to understand I have tried to rephrase it, cant edit the question without understanding it.

    I have an object say User to be saved in database, In my SampleBean.add method I fetch the id by getting the next val of some sequence say userSequence.

    The same value (fetched from userSequence is set as the id of User object.

    Now while persisting the object I am not getting the value of id which I have already set in SampleBean.add method.

    For Persistence I am using PreparedStatement. Can you help me in understanding why is this happening ?

    This part is Answer

    Your are doing a RemoteLookup, and in Java Remote objects are not sent given copy instead it serializes it and sends it, if you want to see the changes done to your object in remove service then you will have to send your object back

    So the code changes required:

    1. Change your insertLogRow method and make it return the object which it has persisted like:

        public LogRow insertLogRow(LogRow logRow) {
           //Do all database operation
           return logRow;
        }
      
    2. Now change the caller code:

       logRow = RemoteLookup.getSampleBean().insertLogRow(logRow);
       log.println("log id " + logRow.logId());
      

    Rebuild, deploy and run.

    Now you should see your id which has been set on the object inside insertLogRow method.

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

Sidebar

Related Questions

Today I came across a new CSS syntax that I have never seen before
I came across an interesting question today where I have two methods that, at
Today I came across this question: you have a code static int counter =
I have been using Perl for some time, but today I came across this
So today I just came across the 'live()' function that binds any future and
I came across this code today AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null); Is there anything wrong with
I came across some javascript at work today that used jQuery to fetch two
I came across some code today that surprised me. A variable was defined (outside
Today I came across this piece of code internal object UpdatePracownik(object employee) { lock
Today I came across a situation where I needed to decide if an entire

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.