I bow to the apover stackoverflow community and humbly seek directions (I bow my head in submission when I write this)
I have the following Entity / bean class that has a mix of JPA / EclipseLink / JAXB / Moxy annotations: (btw EventBase is just @MappedSuperclass that contains extra fields)
@Entity @Table(name = "EVENTS") @XmlRootElement public class Event extends EventBase { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @XmlAttribute(name = "id") private long eventCID; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "APPLICATIONCID") private CustomerApplication customerApplication; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CUSTOMERCID") private Customer customer; .... }
Here is my code for marshaling this object (an external class is excluded for brevity)
public static void main(String args[]) { Event event = myInstance.populateEvent(); myInstance.buildXMLFromEvent(event); } public Event populateEvent() { EntityManagerFactory emf = Persistence.createEntityManagerFactory(this.persistenceUnit); EntityManager em = null; Event event = null; try { em = emf.createEntityManager(); event = (Event) em.createQuery("Select object(e) from Event e where e.eventCID = 55000").getSingleResult(); em.clear(); em.detach(event); em.close(); em = null; emf.close(); emf = null; } catch (Exception e) {
The generated xml really sends and readily retrieves all the member objects of the Event bean! ie) Customer, CustomerApplication, and any other mappings that I excluded for brevity. I use EclipseLink as my provider of JPA and Moxy for JAXB. What am I doing wrong here? You can see that not only the entityManager AND entityManagerFactory instances are cleaned, closed, and set to zero, but I also went ahead and detached the root Event entity. In addition, the fetchtype property is explicitly set to LAZY!
How is it that JAXB can look forward to when an Event object has been detached? I thought closing an entityManager by itself separates all managed objects? Is there any cached session context that JAXB hangs on? If so, why doesn't he even follow a clearly defined sampling strategy? Thank you very much in advance!
Ustad
ustad source share