persistence@glassfish.java.net

Re: Need a reference to an Session Bean within an Entity Bean

From: Kem Elbrader <kem.elbrader_at_gmail.com>
Date: Wed, 1 Aug 2007 09:34:02 -0600

I understand that @Transient "means" don't populate and don't write
but I need a way to keep JPA from populating the field since it
doesn't even exist in the database that JPA is using.
Would updateable=false do this? Is there another way to mark a field
as not being used by JPA that doesn't "mean" that it won't be
persisted somewhere?

On 7/31/07, Marina Vatkina <Marina.Vatkina_at_sun.com> wrote:
> Kem,
>
> You should be able to mark the existing fields as 'updateable=false' but
> @Transient means not only to skip during write to the database, but also never
> populate during the read.
>
> Regards,
> -marina
>
> Kem Elbrader wrote:
> > Here's the situation.
> >
> > A company uses a database that stores information about its customers.
> > A web interface is available for customer service representatives to
> > update the customers name, phone number, etc. The web interface is not
> > suitable for customers to use so the company has a calling center that
> > enables the customers to request changes. The database and web
> > interface were produced by a third party which is unwilling to make
> > changes to the existing system. The third party does provide a web
> > service with operations to create, update, and delete the data.
> >
> > The company wants to provide a web interface to allow customers to
> > update their information themselves. Further, the company wants to
> > produce additional services which will require extra data that is not
> > stored in the original database. For example, some of the entities
> > represented in the original database simply need some properties added
> > to them. It's not viable to reproduce the existing system. So a new
> > system must be created that is capable of updating the data in the
> > existing system, persist the new data and provide the new
> > functionality.
> >
> > I was hoping I could use JPA to model the new and old data together so
> > that a single object could be used in the cases where simple
> > properties need to be added to the existing entities. Is this
> > reasonable?
> >
> > Here is my current approach.
> >
> > @Entity
> > @EntityListeners({UserListener.class})
> > class ExampleUser {
> > @Id String login; // new data
> > @Transient String name; // existing data
> >
> > String getLogin() { return login; }
> > void setLogin(String login) { this.login= login; }
> >
> > String getName() { return name; }
> > void setName(String name) { this.name = name; }
> > }
> >
> > class UserListener {
> > @PostLoad void initializeUser(Object entity) {
> > // use web service to obtain the users name
> > // copy the name to ExampleUser.name
> > }
> > @PostPersist void saveUser(Object entity) {
> > // use web service to save ExampleUser.name
> > }
> > }
> >
> > I believe this is similar to your suggestion but I'm not quite sure
> > what you meant. Can you clarify your suggestion?
> >
> > On 7/30/07, Craig L Russell <Craig.Russell_at_sun.com> wrote:
> >
> >>Hi Kem,
> >>
> >>Can you model this as an EJB that is created by other EJBs and that
> >>contacts the third party web service plus the Entity?
> >>
> >>Craig
> >>
> >>On Jul 30, 2007, at 11:47 AM, Kem Elbrader wrote:
> >>
> >>
> >>>I have an entity which has a few properties that aren't persisted to
> >>>the database but rather obtained from a third party web service. How
> >>>would you suggest going about accomplishing this?
> >>>
> >>>On 7/30/07, Craig L Russell <Craig.Russell_at_sun.com> wrote:
> >>>
> >>>>Hi Kem,
> >>>>
> >>>>I'd suggest you rework your design such that you only use references
> >>>>"from" EJBs "to" Entities and other EJBs.
> >>>>
> >>>>Having Entities reference EJBs violates the basic POJO model.
> >>>>
> >>>>Regards,
> >>>>
> >>>>Craig
> >>>>
> >>>>On Jul 30, 2007, at 11:22 AM, Kem Elbrader wrote:
> >>>>
> >>>>
> >>>>>Is it possible to inject an EJB into an Entity? If not is there
> >>>>>another way to get a reference to a EJB from an Entity?
> >>>>>
> >>>>>Example:
> >>>>>
> >>>>>@Entity
> >>>>>public class Customer {
> >>>>>
> >>>>> @EJB
> >>>>> CustomerAction customerAction;
> >>>>>
> >>>>> @PostLoad
> >>>>> void initialize() {
> >>>>> // do stuff with customerAction...
> >>>>> }
> >>>>>}
> >>>>
> >>>>Craig Russell
> >>>>Architect, Sun Java Enterprise System http://java.sun.com/products/
> >>>>jdo
> >>>>408 276-5638 mailto:Craig.Russell_at_sun.com
> >>>>P.S. A good JDO? O, Gasp!
> >>>>
> >>>>
> >>>>
> >>
> >>Craig Russell
> >>Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> >>408 276-5638 mailto:Craig.Russell_at_sun.com
> >>P.S. A good JDO? O, Gasp!
> >>
> >>
> >>
>