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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:33:24+00:00 2026-06-02T17:33:24+00:00

I have a table with 2 main columns: name and name without accent. I

  • 0

I have a table with 2 main columns: name and name without accent.
I would like hibernate to update the 2nd one when 1st one is changed:

@Column(name = "name")
public String getName() {
    return this.name;
}

public void setName(String s) {
    this.name = s;
    this.noAccentName = RemoveDiacritics(name);  //remove diacritics from name
}

@Column(name = "noaccent_name")
public String getNoAccentName() {
    return this.noAccentName;
}

public void setNoAccentName(String s) {
    this.noAccentName = s;
}

This is working but it has an overhead: setter of the name sets object to dirty, and hibernate wants to update it all the time… 🙁

How can I ask hibernate to update ‘noAccentName’ when ‘name’ was changed in a clean way?

Thanks a lot.

  • 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-06-02T17:33:25+00:00Added an answer on June 2, 2026 at 5:33 pm

    You found the Interceptor, but as of Hibernate 4 the recommended way of doing things like this is to use Callback methods. In fact, I can’t find interceptors in Hibernate 4 at all, so you might not have an upgrade path if you go that way.

    I believe what you want to do is this:

    @Column(name = "name")
    public String getName() {
        return this.name;
    }
    
    public void setName(String s) {
        this.name = s;
    }
    
    @PrePersist
    private void updateNoAccentName() {
        this.noAccentName = RemoveDiacritics(this.name);
    }
    
    @Column(name = "noaccent_name")
    public String getNoAccentName() {
        return this.noAccentName;
    }
    
    private void setNoAccentName(String s) {
        this.noAccentName = s;
    }
    

    Hibernate will then take responsibility for updating the noAccentName just before saving the object. Note that I also made the setNoAccentName method private, as there is no way to convert from noAccentName to name and get the accents right.

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

Sidebar

Related Questions

I have four different tables, one main SPECIAL table containing only id's that reference
I have a table named master with columns id , name , surname ,
Let's say I have a Students table on my main page, with Country, Name,
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
I have a main Table, with several child tables. TableA and TableAChild1 and TableAChild2.
I have a SQL Server database with 500,000 records in table main . There
I have a structure where the main table is USER, other tables include CATEGORY
I have a table naming related_products, Where products_id is the main product. and related_products_ids
I have 3 tables I need to join. The contracts table is the main
I have a question regarding the design of two tables. Table 1: The main

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.