-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: RESOLVED: Inheritance.JOINED strategy and Generated Id
PostPosted: Tue Mar 23, 2010 7:20 am 
Newbie

Joined: Wed Oct 17, 2007 3:18 am
Posts: 3
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?


Last edited by damlobster on Thu Mar 25, 2010 4:33 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Inheritance.JOINED strategy and Generated Id
PostPosted: Thu Mar 25, 2010 8:47 am 
Newbie

Joined: Wed Oct 17, 2007 3:18 am
Posts: 3
If I create a new specific offer (OffreLaa) and save it, I get the same exception.

Tell me if informations are missing in my post.

Thank you in advance for any help!


Top
 Profile  
 
 Post subject: Re: RESOLVED: Inheritance.JOINED strategy and Generated Id
PostPosted: Thu Mar 25, 2010 4:44 pm 
Newbie

Joined: Wed Oct 17, 2007 3:18 am
Posts: 3
The problem came from the @GenericGenerator and @GeneratedValue annotations placed in the wrong class.

***********************************************************************************
***********************************************************************************
@MappedSuperclass
public abstract class AbstractA implements Serializable {

protected Long id;

public AbstractA() {
}

@Id
@GeneratedValue(generator = "generator")
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}

***********************************************************************************
***********************************************************************************
@javax.persistence.Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "a", schema = "public")
@AttributeOverride(name = "id", column = @Column(name = "id", insertable = false, updatable = false))
@GenericGenerator(name = "generator", strategy = "org.hibernate.id.SequenceGenerator", parameters = @Parameter(name = "sequence", value = "public.a_id_seq"))
public class A extends AbstractA {

public A() {
}


@Id
@GenericGenerator(name = "generator", strategy = "org.hibernate.id.SequenceGenerator", parameters = @Parameter(name = "sequence", value = "public.a_id_seq"))
@GeneratedValue(generator = "generator")
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.