@Entity
public class IdType implements Persistable
{
/**
* User specified Unique identifier.
* Both idTypeCode and idCategory are together
* a compound key, so as to ensure that the
* combination of the both can not occur more
* than once in the table.
*/
@Id
public String idTypeCode;
@Id
public IdCategory idCategory;
public String idTypeName;
}
@Transactional
public Result updateIds()
{
IdType idType = Form.form(IdType.class).bindFromRequest().get();
System.out.println("idTypeCode is: "+idType.idTypeCode);
EntityManager em = entityManager();
em.merge(idType);
return redirect(routes.Application.index());
}
idTypeCode is: a-value-from-my-form
[error] - org.hibernate.engine.jdbc.spi.SqlExceptionHelper - NULL not allowed for column "ID_TYPE_CODE"; SQL statement:
insert into id_type (id_type_name, id_type_code, id_category) values (?, ?, ?) [23502-187]
[error] - play.core.server.netty.PlayDefaultUpstreamHandler - Cannot invoke the action
javax.persistence.RollbackException: Error while committing the transaction
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:86) ~[hibernate-entitymanager-5.0.5.Final.jar:5.0.5.Final]
at play.db.jpa.DefaultJPAApi.withTransaction(DefaultJPAApi.java:142) ~[play-java-jpa_2.11-2.4.4.jar:2.4.4]
at play.db.jpa.JPA.withTransaction(JPA.java:159) ~[play-java-jpa_2.11-2.4.4.jar:2.4.4]
at play.db.jpa.TransactionalAction.call(TransactionalAction.java:16) ~[play-java-jpa_2.11-2.4.4.jar:2.4.4]
UPDATE!!!!!
OK, finally got the time to look further into this myself. It seems this has nothing to do with play. I tested just now the same scenario with a straight JPA/Hibernate console app. I get the same problem. The problem occurs as soon as I have a composite key (as I do in the given example). As soon as I remove one of the columns as key, the merge will work. Now I am investigating why that is, and how to avoid the issue (while still having the model I need). I will update this issue as soon as I have more information.