that's very surprising to me as well...
I wonder why the following does not load the LAZY collections...
Code:
EntityManager em = emf.createEntityManager();
Master master;
master = em.find(Master.class, 1L);
em.getTransaction().begin();
em.merge(email);
em.getTransaction().commit();
em.close();
why does it behave differently if detached?
and for me, it goes one step further.. it loads not only the collections in Master, but loads the ones in Detail as well.. which has more collections... causing hundreds of thousands of records to be loaded, it literally sits at my em.merge() for a good 5 minutes
this is my code
Code:
@Entity
@Table(name = "email")
public class Email implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "emailid", nullable = false)
private Long emailid;
@JoinColumn(name = "userid", referencedColumnName = "userid", nullable = false)
@ManyToOne
private Users user;
...
}
@Entity
@Table(name = "users")
public class Users implements Serializable
{
@Id
@Column(name = "userid", nullable = false)
private Integer userid;
@JoinColumn(name = "companyid", referencedColumnName = "companyid")
@ManyToOne(fetch = FetchType.EAGER)
private Companies companyid;
...
}
@Entity
@Table(name = "companies")
public class Companies implements Serializable
{
@Id
@Column(name = "companyid", nullable = false)
private Integer companyid;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "companyid")
private Collection<Activity> activityCollection;
...
}
@Entity
@Table(name = "activity")
public class Activity implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
...
}
and the following code causes the activity collection to be loaded..
Code:
EntityManager em = emf.createEntityManager();
Email email = em.find(Email.class, 13436L);
em.clear();
email.setStatus("test");
em.getTransaction().begin();
em.merge(email);
em.getTransaction().commit();
I am switching from EclipseLink, and as you said, it behaves as I would expect
Derek