Skip to main content

[jsr338-experts] proposal : @Entity on interfaces

  • From: Steve Ebersole <steve.ebersole@...>
  • To: jsr338-experts@...
  • Subject: [jsr338-experts] proposal : @Entity on interfaces
  • Date: Fri, 09 Mar 2012 12:04:48 -0600

I'd like to propose that JPA 2.1 allow @Entity on Java interfaces not just classes. The main reason is typing in spec contracts. For domain models that leverage interfaces, it is usually desirable to deal with the interfaces over the implementation classes. For example, such applications would generally prefer to attempt to load or get a reference to an instance based on the interface name as opposed to the class name. E.g.

public interface Person {
    ...
}

@Entity
public class PersonImpl implements Person {
    ...
}

EntityManager em = ...;
Person p = em.find( Person.class, theKey );

But this does not work today in a portable manner. To work in the most portable manner, I think the @Entity annotated interface also would need to name the "persistent implementation class":

@Entity( impl = PersonImpl.class )
public interface Person {
    ...
}

public class PersonImpl implements Person {
    ...
}

It could be up to each provider whether or not to support @Entity on an interface that did not specify a "persistent implementation class".

Another way to look at this is as basically "aliasing" the entity type metadata using the interface name instead of the implementation class name.

-Steve


[jsr338-experts] proposal : @Entity on interfaces

Steve Ebersole 03/09/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Oliver Gierke 03/09/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Steve Ebersole 03/09/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Bernd Müller 03/11/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

michael keith 03/11/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Matthew Adams 03/12/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

michael keith 03/12/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Oliver Gierke 03/12/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Werner Keil 03/12/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

michael keith 03/12/2012

[jsr338-experts] Re: proposal : @Entity on interfaces

Oliver Gierke 03/12/2012
 
 
Close
loading
Please Confirm
Close