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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:45:55+00:00 2026-06-18T06:45:55+00:00

Right now we have a JPA entity defined as: @Entity @Table(name=Foo) public class Foo

  • 0

Right now we have a JPA entity defined as:

@Entity
@Table(name="Foo")
public class Foo extends ParentClass {
...
}

Imagine that some Foo objects have been persisted in the database already. What would be the best way to programmatically change those persisted records to a sibling subclass of type Bar?

@Entity
@Table(name="Bar")
public class Bar extends ParentClass {
...
}

We do not want to change the database schema, just the entity type of the already persisted Foo objects. I am hoping there is a better method than the only one I have thought of, which is manually grabbing the Foo objects, remapping to Bar, and re-persisting.

  • 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-18T06:45:56+00:00Added an answer on June 18, 2026 at 6:45 am

    Particularly I prefer to do it using pure SQL migration. In my company we use liquibase to version our database schema. So, to do the migration we just create changelogs for it.

    Some argue that it’s not the best solution, but I find it simple and quite powerful. In my opnion, for big projects it’s the way to go.


    EDIT:

    Now that I see that you can’t change the schema. I don’t think this is possible in an easy way programmatically. You would need somekind of “TransformerService” between Foo and Bar, that simply copies the common parent fields, deletes the old Foo and persist the new Bar.

    What I would do is to break the hierarchy and componentize ParentClass, so you can transfer only it between Foo and Bar, viceversa. This way you won’t need to copy the fields or anything like that. It may need a lot of refactoring, but componentizing is better than creating big/complex hierarchies.

    Or you can just run an SQL that changes the object directly at database. It’s ugly, but it’s the only way I see you could do something like that.

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

Sidebar

Related Questions

Right now I have a function, in a class that is used to listen
Right now I have a script that will get the last five files in
Right now I have a link that causes a hidden div to appear when
Right now I have a foreach loop that grabs the first link with an
Right now I have a PHP file that does a MYSQL query and then
I have about 10 different entities in my J2EE application that right now share
In my application right now I have one project which contains all the JPA
I have a standalone java application, which uses JPA for its persistence. Right now
I right now have a comet page, that if i call session_start at the
Right now I have the following html table: <table id=datatable> <thead> <th>fruits</th> <th>vegs</th> </thead>

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.