Menu

Created entity/object overwrites entity/object with similar primary key

Anonymous
2013-04-20
2013-04-24
  • Anonymous

    Anonymous - 2013-04-20

    Hey, really love your generator keep up the great work.
    On with the post; If you create entity/object with a primary key similar to another entity/object already in the database the old one is overwritten by new one.Solution:

    in the AbstractController class/bean make the following changes to the persist method:

    private void persist(PersistAction persistAction, String successMessage) {
    if (selected != null) {
    this.setEmbeddableKeys();
    try {
    if (persistAction == PersistAction.CREATE) {
    this.ejbFacade.create(selected);
    }else if (persistAction == PersistAction.UPDATE) {
    this.ejbFacade.edit(selected);
    }
    else {
    this.ejbFacade.remove(selected);
    }
    ....
    }

    original class didn't have else if (persistAction == PersistAction.UPDATE) but had if (persistAction != PersistAction.DELETE) {
    this.ejbFacade.edit(selected);

    therefore if created an entity with a primary key as another entity already in the database, the new entity would overwrite already existing entity.By the way this is for version 0.13

     
  • Kay Wrobel

    Kay Wrobel - 2013-04-24

    Thank you anonymous. This is similar to what was described to me by another user and I think that your solution would address that issue. Maybe... Another suggestion was to create a custom PrimaryKeyValidator and on the Create.xhtml page raise a validation error. Unfortunately, I haven't had time on investigating that idea further. What do you think?

     

Anonymous
Anonymous

Add attachments
Cancel