• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is JPA discourages use of interface?  RSS feed

Nachiket Patel
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

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

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!