Hibernate does not support changing an object's primary key, as this primary key identifies the database row loaded entities correspond to. Hence changing an object's primary key severs the connection of that loaded entity to the original record in the database, preventing that record from being updated. In particular, if two processes have loaded the same entity, and one process changes his entity's key, the object is "forked", i.e. the two processes now hold different entities, and updates to one entity will not become visible to the other. This unintuitive behavior is why updating keys is strongly discouraged.
However, you can delete an entity and create an entity with similar state, but different key. If this is good enough, you can do:
Code:
session.deleteFlushEvict(entity);
entity.setKey(...);
session.persist(entity);