Uli,
Using Object for key fields is a standard micro pattern in JPA and Hibernate. Of course, the DB does not want to save null as a key field value, but the most people get the entity manager to auto-generate keys for their objects.

By leaving the key as null, the entity manager knows that it needs to persist the object, generating a key for it. This is a handy pattern, when you want to create a parent object with several children, and then persist the whole object tree in one call (otherwise, you would have to persist the tree, one object at a time, from the bottom up - Yikes!). JPA/Hibernate can only do this if it knows what a null key value is, and in Java that is of course, null. I think (from memory) you can define a specific value as a null, so you could use an int or a long as a key field type, and then specify, for example, -999, as the null value. Then, you have to set the key field to -999 somewhere, and this is all too much work for most people, therefore, they use Object key field values!

Ciao,
Jonathan
On 10/02/2009 08:08, Ulrich Stärk wrote:
Thiago H. de Paula Figueiredo schrieb:
Em Mon, 09 Feb 2009 22:35:52 -0300, Luther Baker <lutherba...@gmail.com> escreveu:

Simply stated, I'm asking about the two orthogonal choices: (native vs
object, range or size)
Is an int preferred to an Integer? Is there a compelling argument for either native or Object?

I guess that you mean "primite" when you mean "native".
Native types in Java can't have null values, so, for primary key properties, a Integer is a much better fit than an int.

Why is that? I couldn't imagine a case where you want your primary key value to be NULL (apart from the fact that I don't know any DBMS that allows that).

Uli

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to