• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is JPA discourages use of interface?

 
Nachiket Patel
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am working in J2EE since last 3-4 months. Currently understanding (or i should say it learning) JPA.

As per my knowledge, JPA does not support use of interface(as a persistent attribute) in entity classes. I tried to get information about it, but in vain. Few people suggested to have a look at EclipseLink(which has facility to persist from interface reference), but i am against using any vendor specific features.

FOR EXAMPLE--------------------------------------------------
Say Account is interface and SavingAccount and SalaryAccount classes are implementing Account interface.

Then class Client is having Account as a attribute. (named account)
so there will be statements like

private Account account;
public Account getAccount() {.........
public void setAccount(Account act) {.........


How to persist Client class??
----------------------------------------------------------------

And not using interface is bad practice, right?

As Erich Gamma said Program to an interface not to an implementation. Now that is not possible with JPA right?

I got many answer which tells me to use abstract classes . But it is not an option for interface.

So,
Is there any workaround?
What is your approach?
Or
People just accepted it.

-Nachiket
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic