0 Replies Latest reply on Jul 5, 2006 1:29 PM by Juliana Marcal

    Many to many relationship problem with auto-increment pk

    Juliana Marcal Newbie

      I?m using CMP entity beans. I have an entity HistoricoEstudo whose primary key is auto-increment. I have a relationship many-to-many between this entity HistoricoEstudo and Pessoa. I have configured jboss.xml with <insert-after-ejb-post-create>true</insert-after-ejb-post-create> for entity HistoricoEstudo, so the insert is executed only after all relationships are set on ejbPostCreate.

      When I try to create a new entity HistoricoEstudo I get an error because the container tries to use the value 0 (not the value resulted from the auto-increment) as the foreign key for the relationship HistoricoEstudo-Pessoa.

      If I make <insert-after-ejb-post-create>false</insert-after-ejb-post-create> the value used as the foreign key in the many-to-many relation is the one resulted from auto-increment, but then the not null constraints are violated, since the object is inserted before the other relations are set on ejbPostCreate.

      Does anybody know how to solve this problem?