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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:25:03+00:00 2026-05-23T09:25:03+00:00

I’m gonna try to explain my problem as well I can I have some

  • 0

I’m gonna try to explain my problem as well I can
I have some user groups to manage user rights.

Some users may be customers. There’s a OneToOne connection between the user table and the customers table. And a OneToOne connection between users and groups. When I delete a client, I would like the user group changes from customer to user, the default group (Id=4).

With this code:

    public static void delete(Long id) {
       Customer entity = Customer.findById(id);
       User entityUser = User.findById(entity.user.id);

       entity.delete();

       entityUser.groups.id = (long)4;

       entityUser.merge();
       entityUser.save();

       flash.success(Messages.get("Users.deleted"));
       Customers.list();

   }

Group model:

    @Entity
@Table(name = "groups")
public class Group  extends Model{

   @Required
          public String name;
   @Required
   public String description;
   public Group(String name, String description)
   {
       this.name = name;
       this.description = description;
   }

User model:

  @Entity
@Table(name = "users")
public class User extends Model{


   @Required
           public String firstname;
   @Required
           public String lastname;
   @As("dd/MM/yyyy")
   @Required
           public Date birthday;
   @Required
           public String avatar;
   @Required
           public String adress;
   @Required
           public String phonenumber;
   @Required
   @Email
           public String email;
   @Required
           public String username;
   @Required
   @Password
           public String password;
   @OneToOne
   @Required
           public Group groups;

   public User(
           String firstname,
           String lastname,
           @As("dd/MM/yyyy") Date birthday,
           String avatar,
           String adress,
           String phonenumber,
           String email,
           String username,
           String password,
           Group groups
           )
   {
       if(groups == null){
           groups.id = (long)4;
       }
       else
       {
          this.groups = groups;
       }
       this.firstname = firstname;
       this.lastname = lastname;
       this.birthday = birthday;
       this.avatar = avatar;
       this.adress = adress;
       this.phonenumber = phonenumber;
       this.email = email;
       this.username = username;
       this.password = password;




   }

Customer model:

 @Entity
@Table(name = "customers")
public class Customer extends Model{

   @As("dd/MM/yyyy")
   public Date dateinscription;
   public Double amountdue;
   public Double amountpaid;
   @Required
   public String picture;
   @OneToOne
           public User user;

   public Customer(@As("dd/MM/yyyy") Date dateinscription, Double amountdue, Doubleamountpaid, String picture, User user)
   {
       this.dateinscription = dateinscription;
       this.amountdue = amountdue;
       this.amountpaid = amountpaid;
       this.picture = picture;
       this.user = user;


   }


}

But I’ve got an error:

PersistenceException occured : org.hibernate.HibernateException: identifier of an instance of models.Group was altered from 3 to 4

In /app/controllers/Customers.java (around line 69)
65:

66:
entityUser.groups.id = (long)4;
67:

68:
entityUser.merge();
69:
entityUser.save();
70:

71:
flash.success(Messages.get(“Users.deleted”));
72:
Customers.list();
73:

74:
}
75:

I tried with GenericModel but it didn’t work.

Please help me !!

Thank you.

  • 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-23T09:25:03+00:00Added an answer on May 23, 2026 at 9:25 am

    In your code, you are explicitly changing the ID of the group, not the group. Hibernate assumes you want to change that field. But when you try to save the change, it won’t let you, since it’s the ID. It doesn’t assume you mean “change the group to the one that has an ID of 4.”

    Instead, you’ll need to load the default group, and set the user’s group that that group.

    Group group = Group.findById(4);
    entityUser.groups = group;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.