Thanks for your input. An additional argument here might be that if you are
not the only developer working on your EJB system, and if the system is to
be maintained and expanded over time by many different software developers
in a large organisation, it would probably be best to use only a single type
of key for the same EJB (both in the bean class files and in the xml
files) - and that would have to be the wrapper class, of course.
- All these mails confirm that using different kinds of keys cause
confusion, and I see no reason to confuse future developers of a system.
But that is my personal view of course - and from the systems I have met so
far in my career I sure know that not all developers think this way.

Randahl

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Michael A
Third
Sent: 1. marts 2001 17:46
To: Orion-Interest
Subject: RE: Database schema type mappings


I went digging through the EJB 1.1 specification, and it doesn't
specifically say you can't use primitive types, but it does say they primary
key class needs to be serializable.

I have created a number of EJB's using the primitive long as the primary key
and have had no problems using them.  So I went back and looked at the
deployment descriptor (it was originally generated by EJBMaker) and noticed
that they <prim-key-class> was "java.lang.Long".  All of the EJB class files
are using the primitive type.  It appears that at least Orion maps them
intelligently(if not according to spec).

On closer examination of the EJB 2.0 spec, I found these statements.

* The primary key type must be a legal Value Type in RMI-IIOP. (this
includes long)
* The container must be able to manipulate the primary key type of an entity
bean.
* Primary key (must be a class or type?) that maps to a single field in the
entity bean class.
* The (create) method must declare the primary key class as the method
argument.

According to this statements, the primary key class and the primary key type
don't necessarily have to be the same.  Orion does allow the create method
to accept the primary key type as opposed to the class, which isn't
according to spec.

Thanks,

Michael

PS - After my response on Java primitive data-types, I should probably keep
my mouth shut for a while :)


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Jeff Schnitzer
Sent: Thursday, March 01, 2001 6:12 AM
To: Orion-Interest
Subject: RE: Database schema type mappings


It's at the bottom of page 159 of Richard Monson-Haefel's _Enterprise
Java Beans, 2nd Ed_:  "Although primary keys can be primitive wrappers
(Integer, Double, Long, etc.), primary keys cannot be primitive types
(int, double, long, etc.)"

I wasn't able to locate an explicit statement in the spec in my quick
scan, but the spec always refers to the primary key as the "primary key
class" and the deployment descriptor element is "prim-key-class".  This
is further reinforced by the comments in the DTD.

It makes sense, because EntityContext.getPrimaryKey() returns an Object.
Thus all PKs *must* be Objects.

About question #1:  I doubt there is any explicit requirement in the
spec that Integers be converted to ints in the database.  In fact, the
spec doesn't require a relational database; that's simply an
implementation detail.  Still, I doubt you will find *any* appservers
which serialize Integer keys as blobs - although it would work, the
performance penalty would be severe.

Jeff

>-----Original Message-----
>From: Randahl Fink Isaksen [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, March 01, 2001 1:22 AM
>To: Orion-Interest
>Subject: RE: Database schema type mappings
>
>
>Thanks for the reply Jeff. Know I have two replies: One saying
>primary keys
>can be primitive types and one that says they can't.
>I am really looking forward to hearing your arguments, gentlemen ;-)
>
>BTW, Jeff: Your answer to question number 1 - do you have that from the
>specification, or...
>
>Randahl
>
>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED]]On Behalf Of Jeff
>Schnitzer
>Sent: 1. marts 2001 02:52
>To: Orion-Interest
>Subject: RE: Database schema type mappings
>
>
>>From: Randahl Fink Isaksen [mailto:[EMAIL PROTECTED]]
>>
>>1. Why is Integers automatically converted to int by Orion -
>>and is this a
>>standard EJB convention?
>
>Yes.  All the class representations of the primitive types should work
>that way.
>
>>2. Would it be legal to have a primary key of the primitive type "int"
>>instead of Integer?
>
>No.  Primary keys must be Objects.  This makes sense because
>EntityContext.getPrimaryKey() returns an Object.
>
>Jeff
>
>
>


Reply via email to