how to persist an object twice into two diff. collections of two diff. classes


ok my problem, 


i persist a Squad Object into a Cup Object at the beginning, after i have to create and persist a competition object in which i have to put some of the already created/persisted squads. the final method looks like that:

public void actionPerformed(ActionEvent e) {
    List<Squad> selectedSquads = new ArrayList<Squad>();
        if (tableSquads.getSelectedRows().length > 0) {
             int[] rows = tableSquads.getSelectedRows();
             DBConnection db = new DBConnection();
             Competition tmpComp = db.getEm().find(Competition.class, actualCompetition.getId());
             for (int i : rows) {
                  int modelRow = tableSquads.convertRowIndexToModel(i);
                  Squad tmpSquad = gymCupController.getGymCup().getUnallocatedSquads().get(modelRow);




This code will throw this exception:

Exception in thread "AWT-EventQueue-0" [ObjectDB 2.2.0] javax.persistence.RollbackException
Failed to commit transaction: Attempt to reuse an existing primary key value (ch.hsr.gymtastic.domain.Squad:1) (error 613)
    at com.objectdb.jpa.EMImpl.commit(
    at ch.hsr.gymtastic.technicalServices.database.DBConnection.commit(
     at ch.hsr.gymtastic.server.presentation.frames.SquadsSelectionFrame$2.actionPerformed(

so how can i trick the DB?



i apreciate ur ideas!!!!¨


Just delete the db.persist(tmpComp); line.

No need to call persist in order to update an already managed entity object.

See the Updating Entity Objects page in the manual and this forum thread.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login