Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

JPA: How to fetch primary key dynamically

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have been working with JPA from past few months.
Recently, I am involved in writing EJB3 statless bean, Interceptor & JPA.

Before manager's (statless bean's) method gets invoked, I am intercepting it through interceptor.

In my manager method, I am annotating some arguments (entities) as
a custom annotation.

In my interceptor, i need to check if that argument (entity) exists in Data Base or not.

For normal entites, i know, i can perform it like this:

But , I have more than 100 methods spread across some 10 - 15 managers ( with 30- 40 entities ) !
& I feel this will surely be a cross cutting concern ...

I have decided to go like this :

In My interceptor though, I get only
and i need to check if that object (which is actually entity) actually exists in a data base or not

Hope I am clear with my requirement ...

My questions are following: Is there a way in JPA API,

1) To check if the is an entity or not

2) To fetch the primary key dynamically from as

3) If above 2 do not exist, a way to check if entity exists in DB, in some other manner, which solves my requirement

Thanks a lottt

Thanks in advance .....

Waiting for your valuable response ...


You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic