خرید بک لینک

Vote count: 0

I've been looking around and around without finding any topics related to my situation.

I'm using:

  • Play! framework v2.5.3 in Java
  • Hibeate EntityManager v5.1.0.Final
  • Hibeate JPA 2.1 API v1.0.0.Final
  • PostgreSQL 9.4

Here the route called with AJAX:

PUT /admin/entity/:id

Which is bound to:

controllers.Entity.update(id: Long)

Here how I handle the update request:

@play.db.jpa.Transactional
public Result update(final long id) {
  EntityManager em = _jpa.em("default");
  DynamicForm form = _formFactory.form().bindFromRequest();
  models.Entity entity;

  entity = em.find(models.Entity.class, id);
  if (entity == null)
    retu badRequest();
  entity.update(em, form);
  em.merge(entity);
  retu ok();

The method update of Entity change values of the class attributes which are basically String attributes.

My issue: nothing get updated while still executing this piece of code. I enable SQL log which only display the SELECT query corresponding to em.find() method call. Nothing related to an UPDATE query.

I've been using JPA/EntityManager with Play! for others projects (but with lower version of the framework) without facing this kind of problem.

Any idea why nothing get merged ?

I've been able to fix this issue by writing following piece of code inside models.Entity.update:

em.getTransaction.begin();
Query query = em.createQuery("UPDATE entity SET value = :v WHERE id = :id");
query.setParameter("value", value);
query.setParameter("id", id);
query.executeUpdate();
em.getTransaction.commit();

But even if this is working, that's not the way how thing should be done... It doesn't make coffee at all!

I really don't know what I'm doing bad, if any body has an idea about this issue, you're help would be much appreciated.

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 24 ارديبهشت 1395 ساعت: 22:56

صفحه بندی