Wednesday, November 25, 2009

Eclipselink: Null primary key encountered in unit of work clone

Remember that XKCD strip about the most boring guy in the world and his blog
where he only apologizes for not writing more? :D Here it is ;)

Well, it's been a while. To be honest, civilian military service is not actually best environment for us developers, but what can you do, from June next year, I'm back on track.

Meanwhile, a blast from the past. I received a notification about a bug on Eclipselink you can find here. Of course, I encountered it last summer. Suddenly a weird error Null primary key encountered in unit of work clone, as the title of this post (I hope it helps with google).

So, this is one of those things that just frustrates you. You develop application, write queries by the book, OK, push the limits probably on few fronts, but it's all according to specification, should work, wright? Yeah, should. But bug like this just kills you. It occurs seemingly randomly, fires up nad causes some null pointer exceptions in upper layers of your application, so you dig in and find thing like this. I can tell you, I've been lucky here. In most cases I just run (actually Google does) into two or three guys who had the same problem (usually our Corean brotheren, hats off ! ), and no solution...

So, it had something to do with assigning sequence numbers. I went so far to dig into the source code of Eclipselink, but honestly, I couldn't get my way around it, even debugging (I'm not proud) didn't help. Guys who discussed the problem on the thread about the bug suggested that the problems are negative ID's which could not occur in our application. At the end, we've given up. And now the blessed news:

Chris Delahunt 2009-11-12 16:13:34 EST
Peter checked in a fix 02 November 2009

I'll check it with the guys at work to see if they still have the same problem
as before and if new patch will help.

This reminds me of a very interesting problem tha led to very
interesting solution,regarding sequencing, concurency and
multiplatform implementation of JPA.
Interested? Well, OK, you will have it in the next blog post which,
I hope will not be seven months from now . :)



5 comments:

  1. Well, I am pleased to say tha team at the office, actually a colleague of mine who shares this blog, has succesfully solved a problem after some debugging of eclipselink. I will let him take the glory, if he wants. You see, a while ago anonymous poster left a comment here, quite insulting, because he felt like wasting time reading this post after not finding solution. I refused to publish it, but the guy gave interesting proposition of donating 60k dollars for the solution. If the offer still stands, I guess Miroslav would be pleased to take the cash.

    ReplyDelete
  2. What is the solution?

    ReplyDelete
  3. Well, unfortunately, one can not say that there is one solution for this problem. In particular case, problem was solved by setting certain eclipselink parameter, but that does not mean it will solve your problem. A colleague attached eclipselink source to Eclipse debugging, simulated situation where error occurs and figured out in particular case that parameter for weaving and changetracking needs to be set. I will leave to my friend who shares this blog to explain this, if he has time, but I repeat, it does not mean that it will solve your problem. It may be something that will be repaired, or already is, in some next version of eclipselink. Solution, therefore, is not easy, at least not for us (couple of days of debugging).

    ReplyDelete
  4. For me, the solution was an oversight. You can't have a primary key set to 0. Apparently it must be >= 1.

    ReplyDelete
    Replies
    1. Hi all,
      Even i am having the same problem. When i'm running my application in my local weblogic deployment this error is not seen. When client is using from many months, now in error log this error is seen very frequently. I verified the database for invalid id's but all are valid and proper. Still i'm getting "Null primary key encountered in unit of work clone" error. Please suggest a solution for this.

      Thanks in advance.

      Delete