Hi,
I've a problem with automatic generation of id for entities with inheritance.
I think it's a problem with my "generator" annotations on the generic offer entity (see below), but I'm not sure. I've other entities without inheritance but with the same "generator" annotation and they work well.
When executing this sequence of code:
Code:
OffreLaa offer= (OffreLaa)session.get(OffreLaa.class, 1L);
session.evict(offer);
offer.setId(null);
session.save(offer);
I get this exception:
Code:
org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually assigned before calling save(): ch.frv.dao.entities.affiliation.Offre;
nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ch.frv.dao.entities.affiliation.Offre]], dirtiesContext [false].
This is the entities hierarchy:
Code:
@MappedSuperclass
public abstract class AbstractHistorizedEntity implements Serializable {
protected Long id;
...
@Id
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return id;
}
...
}
Code:
@MappedSuperclass
public abstract class AbstractHistorizedAndDatedEntity extends
AbstractHistorizedEntity {
...
}
The generic offer entity:
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "offre", schema = "affiliation")
@AttributeOverride(name = "id", column = @Column(name = "id_offre", insertable = false, updatable = false))
public class Offre extends AbstractHistorizedAndDatedEntity {
...
@Id
@Override
@GenericGenerator(name = "generator", strategy = "org.hibernate.id.SequenceGenerator", parameters = @Parameter(name = "sequence", value = "affiliation.offre_id_offre_seq"))
@GeneratedValue(generator = "generator")
public Long getId() {
return this.id;
}
...
}
The specific offer entity:
Code:
@Entity
@PrimaryKeyJoinColumn(name = "id_offre")
@Table(name = "offre_laa", schema = "laa")
public class OffreLaa extends Offre {
...
}
I use a PostgreSQL database.
Can anyone help?