EntityNotFoundException: Failed to get object of view ... when commit

When my servlet tried to write a record, it included the following exception:

javax.persistence.EntityNotFoundException: Could not retrieve entity of kind MyEntity with key MyEntity(1318001) 

even if I checked and ensured that id 1318001 did not exist in my data warehouse. This happened when my servlet completed the translation.

Here is my coding:

 EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional"); EntityManager em = emfInstance.createEntityManager(); em.getTransaction().begin(); MyEntity ent = new MyEntity(....); em.persist(ent); log.info(ent.toString()); em.getTransaction().commit(); 

I can see my ent in the log, but this threw an exception in the commit expression. Can someone please help.

EDIT: @jirungaray @ Nicholas, thanks for your comments. The problem has not been resolved. I ended up adding try and catch to commit() to keep track of when this happened. Now I replaced the application with another and did not encounter the same problem. Here is the object if you are still interested.

 @Entity public class MyEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long key; private String tDate; private int stkCode; private Text tradeRec; public MyEntity() {} public MyEntity(int code, String dd, Text trec) { this.stkCode = code; this.tDate = dd; this.tradeRec = trec; } ..... getter and setter skipped 
+4
source share

Source: https://habr.com/ru/post/1440673/


All Articles