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

The Archive Base Latest Questions

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

I am using Struts2, Spring and Hibernate in my application and database is MySQL

  • 0

I am using Struts2, Spring and Hibernate in my application and database is MySQL 5.5. I have this table in database:

create table if not exists campaigns(
    id int(10) not null auto_increment,
    campaignId int(25) not null unique,
    createdBy int(25) not null REFERENCES users(userId),
    campaignName varchar(255) not null,
    subject varchar(500),
    body varchar(50000),
    modifiedOn TIMESTAMP,
    triggeredOn date,
    numberOfTargets int(10),
    primary key (id, campaignId)
);

And I save and update the “Campaign” objects with the following methods (hibernate-mapping through hbm files) :

public boolean addCampaign(long createdBy, String campaignName) throws NoSuchAlgorithmException {
    Campaign campaignObject = new Campaign();
    SecureRandom generatedHash = SecureRandom.getInstance("SHA1PRNG");
    campaignObject.setCampaignId(new Integer(generatedHash.nextInt()));
    campaignObject.setCreatedBy(createdBy);
    campaignObject.setCampaignName(campaignName);
    getHibernateTemplate().save(campaignObject);
    getSession().flush();
    return true;
}

public Date updateCampaign(String campaignId, String subject, String body) throws NumberFormatException {
    Campaign campaign = getCampaignByCampaignId(Long.parseLong(campaignId));
    if(campaign != null) {
        campaign.setSubject(subject);
        campaign.setBody(body);
        getHibernateTemplate().save(campaign);
        getSession().flush();
        return campaign.getModifiedOn();
    }
    return null;
}

The “modifiedOn” column updates when I run a update query on database. But hibernate is failing to update it. Thanks for your time.

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

    First of all, save is for inserting a new entity. You should not use it when updating an attached entity. An attached entity’s state is automatically written in the database (if changed) at flush time. You don’t need to call anything to have the state updated.

    And Hibernate won’t magically re-read the row it has inserted/updated to get the generated timestamp. A specific @Generated annotation is needed to do that. But it will decrease the performance of the application.

    I would use a pre-insert/pre-update hook to set the modifiedOn value programmatically in the entity, and avoid auto-modified timestamps in the database.

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

Sidebar

Related Questions

I am developing an application using oracle 11g, Java(struts2) and Hibernate. I have table
I needed to create an application using Struts2 as MVC,Hibernate for data access and
For an application, I am using Struts2, hibernate and spring for injection. Any time
I am new to struts2, prior to this I have been using struts1.2, Spring
I'm interested in porting an existing application which was written using Spring/Struts2/Hibernate to GAE.
I have a web application that using Struts + Spring + Hibernate . In
I have a Web application using spring and hibernate and struts (it runs on
I'm using Struts2, Spring, and Hibernate. I have written a simple Excel file called
I have an application written with Struts2 and Spring for DI and I'm using
I am using hibernate, spring, struts framework for my application. In my application, each

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.