1

I think I might be having a problem with Apache Delta Spike. I have a parent entity which is already persisted and I am adding a new child to it. If I use the EntityRepository, I get a duplicate key problem on insert because it must think the parent is not yet persisted:

[code] entityRepository.save(parent); // this throws a duplicate key exception

entityManager.merge(parent); // this works [/code]

The funny thing is, is that I checked the source for CdiQueryInvocationContext, and it is doing the same exact thing I am doing, it checks if the parent has an identifier. If so, it calls merge instead of persist.

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'user-1' for key 'User_Environment'

Any ideas? For the time-being, I'll use entityManager, but that defeats the purpose.

Thanks,

Walter

Walter
  • 1,290
  • 2
  • 21
  • 46
  • We recently had a discussion around transaction management. If I had to guess, you're somehow calling it outside the normal transaction. When this happens, it's trying to do a persist, hence why it's working. Are you enabling transactions somehow? – John Ament Dec 22 '13 at 00:52
  • Hi John, actually, the correct action is to do a merge not a persist. If I manually invoke entityManager.merge(parent), it works. I am invoking this from within a Java EE batch job so I believe that means it is controlling the transactions until the step completes? Even using the @TransactionAttribute doesn't seem to help ... – Walter Dec 23 '13 at 01:45
  • I'd recommend posting to the DeltaSpike user mail alias, will likely get some internal traction. When I mentioned persist I wasn't referring to the method, sorry. – John Ament Dec 23 '13 at 23:27
  • Ok, will do. Ah, just wanted to be sure as often times the most difficult problems are really simple ... if you know where to look. – Walter Dec 27 '13 at 20:25

0 Answers0