users@glassfish.java.net

JPA Id fields???

From: Daniel Cavalcanti <dhcavalcanti_at_gmail.com>
Date: Fri, 17 Aug 2007 14:47:15 -0400

I have an EJB that persists, updates, removes, etc an entity... (create
using NetBeans).
From another EJB, BeanB, I create an entity and use the BeanA to persist.

@Entity
@Table(name = "resource_requests")
public class ResourceRequests implements Serializable {

    @Id()
    @Column(name = "id", nullable = false)
    private BigInteger id;

    @Column(name = "start_date", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date startDate;

    ...

}

@Stateless()
public class ResourceRequestsBean
    implements ... {

    @PersistenceContext()
    private EntityManager em;

    public ResourceRequestsFacade() {
    }

    public void create(ResourceRequests entity) {
        em.persist(entity);
    }

    public ResourceRequests edit(ResourceRequests entity) {
        return em.merge(entity);
    }

    public void destroy(ResourceRequests entity) {
        entity = em.merge(entity);
        em.remove(entity);
    }

    ...

}


@Stateful()
public class SomeBean
    implements ... {

    @EJB()
    private ResourceRequestsFacadeLocal resourceRequestsFacade;

    @EJB()
    private ResourcesFacadeLocal resourcesFacade;

    @EJB()
    private UsersFacadeLocal usersFacade;

    public void requestValet(Users user, String ticket) {

        //
******************************************************************
        // Data tier
        //
******************************************************************

        ResourceRequests request = new ResourceRequests();

        request.setStartDate(new Date(System.currentTimeMillis()));
        request.setResourceId(valet);
        request.setUserId(user);

        valet.getResourceRequestsCollection().add(request);
        user.getResourceRequestsCollection().add(request);

        resourceRequestsFacade.create(request);
        resourcesFacade.edit(valet);
        usersFacade.edit(user);

        request = resourceRequestsFacade.edit(request);

        //
******************************************************************
        // Messaging tier
        //
******************************************************************

        ...

    }

}

Now, in the code after the Messaging tier comments, I need the request
entity id... Which is still NULL.
I've tried many different things, but I can't figure out how to get the
value persisted in the DB. Furthermore, I can't look that entity up because
I don't have the PK?!?

How can I do that?