yubaolee / dddlib

Automatically exported from code.google.com/p/dddlib
0 stars 0 forks source link

The implementation of EntityRepository of JPA (EntityRepositoryJpa) can't save the Entity Object #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an entity object, such as User.
2. Invoke the save() method of User entity instance.
3. The User entity instance can't persistent into the database and can't 
produce the id.
4. Trace the source of EntityRepositoryJpa implementation of save() method:
  public <T extends Entity> T save(T entity)
  {
    Entity result = (Entity)getEntityManager().merge(entity);
    LOGGER.info("save a entity: " + entity.getClass() + "/" + entity.getId() + ".");
    return result;
  }
5. The problem is the save method use the merge() method but not the persist() 
method to save the new Entity instance. I think the merge method should use to 
update an transient or persist entity instance.
6. I suggest to change the merge() to persist() method, and add one more method 
update() to update/merge entity.

Original issue reported on code.google.com by iffiff1@gmail.com on 14 Sep 2012 at 3:21