I've got a problem using Spring 2.5.5, Hibernate 3.2.4.sp1 and Postgres.
I'm using a base class (BaseClass) with common data and a set of subclasses with more information, using a table-per-class schema sharing the same id. That works.
There is now the need to specialize one of the subclasses (SubClass). I've created a new subclass of it (SpecializedSubClass).
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = "SEQ_GEN", sequenceName = "baseclass_sequence", allocationSize = 1)
public class BaseClass {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
} protected Long id;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class
SubClass extends BaseClass {
@Column
private String column1;
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class
SpecializedSubClass extends SubClass {
@Column
private String column2;
}
When I create for the existing objects in the database the new objects that works as expected. But when I try to create a new SpecializedSubClass for an existing SubClass in the runtime I get an error:
Code:
HibernateSystemException: a different object with the same identifier value was already associated with the session
If I evict the SubClass object then I get the following exception:
Code:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [SpecializedSubClass] with identifier [945]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [SpecializedSubClass#945]
To do it I've created a new SpecializedSubClass object copying all the fields of SubClass and assigning it the same id. Is that a wrong way of doing it? Does anybody know how to do it?
Thanks in advance,
Jordi