This error occurs when you try to modify the primary key value of your Entity Class or Model class. Below are some solutions you can follow to solve this problem.
If you're telling Hibernate to use a generator class (@GeneratedValue), maybe manually setting the value of the primary key is what's causing the exception. So either remove @GeneratedValue from your Entity Class or don't try to set the primary key property of Entity class manually.
If you want to modify the primary key value of your Entity class, you will have to first detach your Entity from session. To detach Entity from session you can use the detach() method of EntityManager interface. For more information on detach method, you can refer Oracle JavaEE API
If you are using xml file for bean configuration, then check what is the type of Primary key field that you have used in XML file and what is the type of Primary key field in Entity or Bean class. If both are different, then change anyone of them, so that both the types of primary key field are same.
For ex. in hbm.xml file if Primary key field (say id) has type of integer and in Entity or Bean class primary key field(say id) has type long.
If all the above solution doesn't work, and you have yourself found some solution please write that below in comment sections please. It would surely help others.