openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb_bou <sebastien.boudr...@promutuel.ca>
Subject Same insert statement generated multiple times
Date Mon, 28 Sep 2009 13:28:32 GMT

Hi all!

I'm new to OpenJPA and, with the following mapping, the insert statement of
the child entity is generated three times when I cascade persist an Adherent
instance.  This causes a DuplicateKeyException:

com.ibm.websphere.ce.cm.DuplicateKeyException: DB2 SQL error: SQLCODE: -803,
SQLSTATE: 23505, SQLERRMC: 1;DEV.EAC007_F_LIEN_PARE

I'm stuck with this problem for more than 4 days.  I would really appreciate
any help!

Here is the parent class:

@Entity
@Table(name="F_ADHERANT")
public class Adherant extends Employe implements Serializable {

// primary key is a generated value of type identity located the super class
Employe (ID_EMPLO)
.....
	@OneToMany(cascade = CascadeType.PERSIST)
	@ElementJoinColumn(name = "ID_EMPLO", referencedColumnName = "ID_EMPLO")
	protected Set<LiensParenteHolder> childrenDB = new
HashSet<LiensParenteHolder>();
	private transient List<LienParente> children = new
ArrayList<LienParente>(); // collection of enums

        // I also tried this more standard mapping, but got the same error.
	//@OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST)
	//protected Set<LiensParenteHolder> childrenDB = new
HashSet<LiensParenteHolder>();
	//private transient List<LienParente> children = new
ArrayList<LienParente>();

	@PrePersist
	void populateDBFields() {
		
		for (LienParente lien : this.liensParente) {
			if (!liensParenteBd.contains(lien)) {
				liensParenteBd.add(new LiensParenteHolder(lien));
			}
		}
	}
}

Here the child class:

@Entity
@Table(name="F_LIEN_PARENTE") // this is name of the view.
public class LiensParenteHolder implements Serializable {


    // Primary key of the table is ID_EMPLO(PK, FK) and COD_LIEN_PARENTE(PK)

    @Id
    @Column(name="COD_LIEN_PARENTE")
    @Enumerated(EnumType.STRING)
    private LienParente lienParente;

}
-- 
View this message in context: http://n2.nabble.com/Same-insert-statement-generated-multiple-times-tp3729397p3729397.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message