Ok, I know this isn't on the exam, but I want to practice coding a few beans before I take the test, and I ran into a bit of a mire right out of the gate.
In the real world, is there an accepted or standard way of generating primary keys for entity beans?
Assuming a numeric PK...I've considered having a single go-to bean that reads the max value of the PK field in the database and then increments and doles them out. But if I do this as a bean, then every create() called on that bean's home is going to produce a bean that generates duplicates of every other bean in the pool! (more or less)
Static non-final field/method would seem to be an obvious bet, but they're disallowed.
Helper class? Vendor-specific dealie that I don't know about?
This seems like such a basic issue, but I haven't found any posts about it here....
can you explain a bit more in details? may be some example, if possible?
i am not sure that i understood. :-(
<a href="http://www.BossTalks.com" target="_blank" rel="nofollow">http://www.BossTalks.com</a><br />Free advices and help for entrepreneurs: from Idea to IPO<br />Software and IT Project Management forum
posted 16 years ago
Thanks, Jason. I must admit it took me a few seconds before I slapped my forehead and said "Of course!"
I set up a PRIMARY_KEY table that looks (currently) like this:
PK_PK, EMPLOYEE_PK 1 207
I'm now creating an entity with only one business method, getEmployeePK(). It returns the value of EMPLOYEE_PK and then increments EMPLOYEE_PK. The bean has create methods, and ejbRemove calls setRollbackOnly to keep anyone from removing this one and only row. It seems like a good idea to make the trans-attribute mandatory to make sure that this whole process is part of the calling transaction.
Sound about right?
Is this sort of approach..."industry standard?"
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.