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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:12:41+00:00 2026-05-25T00:12:41+00:00

I have 2 class Item & Type. An Item belongs to one type. It

  • 0

I have 2 class Item & Type. An Item belongs to one type.

It works ok. But when I try to change TYPE of an already saved item, it brings out the error:

identifier of an instance of com.myapp.model.Type was altered from 1
to 2.

It seems that Hibernate is thinking that I try to edit the id of Type. Actually, I want to change the Type of an item, not edit the type it is in. For a quick example, I have an Item name “Ball” belongs to “sport” type, but now I want to change it to “Tool” type. And Hibernate think that I want to change the name (and Id) of “Sport” type into “Tool”!

Pseudo code:

Item item = getItemFromDatabase(itemId);
item.setType(newType);
saveItem(item);

My mapping files:

<hibernate-mapping>
    <class name="com.myapp.model.Item" table="ITEM">
        <cache usage="read-write"/>
        <id name="id" column="ID">
            <generator class="sequence">
                <param name="sequence">item_seq</param>
            </generator>
        </id>

        <property name="name" column="NAME"/>
        <many-to-one name="type" 
             class="com.myapp.model.Type"
             column="type_id" 
             foreign-key="ITEM_TYPE_FK"
              />

        <property name="description" column="DESCRIPTION"/>
    </class>
</hibernate-mapping>

And

<hibernate-mapping>
    <class name="com.myapp.model.Type" table="TYPE">
        <cache usage="read-write"/>
        <id name="id" column="ID">
            <generator class="sequence">
                <param name="sequence">type_seq</param>
            </generator>
        </id>

        <property name="name" column="NAME"/>
    </class>
</hibernate-mapping>

Does I misunderstand anything?

UPDATE:

I have an Hibernate utility function like this:

    @Override
    @SuppressWarnings("unchecked")
    public <T> T getById(Class<T> entityClass, Serializable id) {
        try {
            Object result = this.sessionFactory.getCurrentSession().get(entityClass, id);
            if (result != null) {
                return (T)result;
            } else {
                return null;
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new DataAccessException(e);
        }
    }

Then in my code, I just call:

Type updatedType = repository.getById(Type.class, item.getType().getId());
  • 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-25T00:12:41+00:00Added an answer on May 25, 2026 at 12:12 am

    The way that I think is correct is

    Item item = getItemFromDatabase(itemId);
    item.setType(getItemTypeFromDatabase(newTypeId));
    saveItem(item);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some custom type: [RdfSerializable] public class Item { [RdfProperty(true)] public string Name
i have menu structure like below, <ul> <li class=menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1406
I have a class class Item { int _one; int _two; int _three; //
I have an Item class. There's an itemType field inside of that class which
I have the jquery: $(.item) which gives me all elements of class item. I
I have a Model with a Foreign Key of Parent class Item(models.Model): parent =
I have a datastore model representing items in an ecommerce site: class Item(db.Model): CSIN
I have that situation: I have models Item, Region and Country. class Item(models.Model): name
I have a class like the following: class Positive(object): def __init__(self, item): self._validate_item(item) self.item
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;

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.