RE: Get primary key from persistent bean

2006-12-11 Thread Pinaki Poddar
 This is a major hole in the JPA spec if you ask me.
Once upon a time, there was a spec called JDO. It had a API
javax.jdo.JDOHelper.getObjectId(Object pc);
I think it got left out while copying ;) 


Pinaki Poddar
BEA Systems
415.402.7317  
___
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.


Re: Get primary key from persistent bean

2006-12-11 Thread Marc Prud'hommeaux

Dain-

Note that you could always introspect on the class and look for the  
@Id annotation, and get the value of the Field/Method on which the  
annotation resides. This is pretty heavy-handed, and doesn't work for  
XML mappings, but it is one possible way to do this without making  
assumptions about the underlying vendor.



On Dec 11, 2006, at 5:45 PM, Dain Sundstrom wrote:


On Dec 11, 2006, at 5:34 PM, Craig L Russell wrote:


Hi Dain,

How about

Object pk = bean.getId();


That implies that every persistent bean implements getId().  That  
would work find for the beans I write but not for beans other  
write.  This is a major hole in the JPA spec if you ask me.


-dain




Re: Get primary key from persistent bean

2006-12-11 Thread Craig L Russell

Hi Dain,

I've never seen an @Entity without an @Id annotation. I don't believe  
it is a valid JPA mapping without an @Id. That said, it's not  
required to be named Id.


So are you writing a framework or sample code? For a framework, it  
would be nice to be portable. For sample code, who cares?


Craig

On Dec 11, 2006, at 5:45 PM, Dain Sundstrom wrote:


On Dec 11, 2006, at 5:34 PM, Craig L Russell wrote:


Hi Dain,

How about

Object pk = bean.getId();


That implies that every persistent bean implements getId().  That  
would work find for the beans I write but not for beans other  
write.  This is a major hole in the JPA spec if you ask me.


-dain


Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!



smime.p7s
Description: S/MIME cryptographic signature


Re: Get primary key from persistent bean

2006-12-11 Thread Dain Sundstrom

On Dec 11, 2006, at 6:03 PM, Craig L Russell wrote:


Hi Dain,

I've never seen an @Entity without an @Id annotation. I don't  
believe it is a valid JPA mapping without an @Id. That said, it's  
not required to be named Id.


I'm not using annotations at all.  Everything is done in the mappings  
xml.


So are you writing a framework or sample code? For a framework, it  
would be nice to be portable. For sample code, who cares?


I'm doing both. If I determine that getting the pk from JPA is  
necessary for the framework, I'm just add another method to my non- 
portable jpa wrapper :)


BTW another thing that JPA needs is an equivalent of the OpenJPA  
LifecycleListener.  The interceptor stuff doesn't cut it since beans  
can override the interception and it is just a PIA to get your  
interceptor added to ever bean.


-dain



RE: Get primary key from persistent bean

2006-12-11 Thread Patrick Linskey
 On Dec 11, 2006, at 6:03 PM, Craig L Russell wrote:
 
  Hi Dain,
 
  I've never seen an @Entity without an @Id annotation. I don't  
  believe it is a valid JPA mapping without an @Id. That said, it's  
  not required to be named Id.
 
 I'm not using annotations at all.  Everything is done in the 
 mappings  
 xml.

All entities must have declared identity, but they can use compound
identity.

 BTW another thing that JPA needs is an equivalent of the OpenJPA  
 LifecycleListener.  The interceptor stuff doesn't cut it since beans  
 can override the interception and it is just a PIA to get your  
 interceptor added to ever bean.

You might be interested in the
org.apache.openjpa.event.TransactionListener stuff. Also, note that
OpenJPA allows re-entrancy and full mutability in callbacks and
listeners.

-Patrick
___
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.


Re: Get primary key from persistent bean

2006-12-11 Thread roger.keays



Dain Sundstrom wrote:
 
 This is a major hole in the JPA spec if you ask me.
 

+1 !

I don't use @Id either
-- 
View this message in context: 
http://www.nabble.com/Get-primary-key-from-persistent-bean-tf2796004.html#a7827429
Sent from the open-jpa-dev mailing list archive at Nabble.com.