|
|
|
Re: eclipselink 2.0 and weblogic 10.3.2 integration [message #509559 is a reply to message #509206] |
Fri, 22 January 2010 17:08   |
Eclipse User |
|
|
|
Thank you for replies.
I agree with Duog. Entities should not be merged, after they become managed. It is overhead. But it is not forbidden by JPA specification.
Anyway, I think that I have solved the problem . I didn't mention earlier that, in SE environment everything was fine. Problem appears only in EE (weblogic 10.3.2).
After 2 days of debugging through eclipselink source code and reading documentation I discovered that execution wasn't the same. On application server feature eclipselink.weaving.changetracking was enabled by default. And this thing caused problems.
Now I have this line in my persistence.xml
<property name="eclipselink.weaving.changetracking" value="false"/>
and my example works fine.
Changetracking looks me like nice feature but there is collision with merge operation. By changetracking feature, new entity (Detail) was placed on server cache immediately after it was added in collection in Master entity (method change in Master entity). After that, merge operation didn't assigne sequence into id field of new Detail entity........ because it wasn't new! New entity was already in cache, thanks to changetracking feature.
Validation during flushing discovered that one entity don't have id, and BUM. Quote: | Null primary key encountered in unit of work clone.....
|
Master entity
@Entity
@Table(name = "MASTER")
public class Master implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_GENERATOR")
@SequenceGenerator(name = "ID_GENERATOR", sequenceName = "ID_GENERATOR")
private Long id;
@Version
private Long version;
private String name;
@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="master")
protected List<Detail> details;
public Master() {
details = new ArrayList<Detail>();
}
public void change(String newName){
Detail detail = new Detail(getName(), this);
details.add(detail);
this.name = newName;
}
//setters and getters
}
Detail entity
public class Detail implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_GENERATOR")
@SequenceGenerator(name = "ID_GENERATOR", sequenceName = "ID_GENERATOR")
private Long id;
@Version
private Long version;
private String name;
@ManyToOne
@JoinColumn (name="MASTER_ID")
private Master master;
public Detail() {
}
public Detail(String newName, Master master) {
this.name = newName;
this.master = master;
}
//setters and getters
}
Method in session bean
public Master chamgeNameOfMaster(Master master, String newName){
master = em.find(Master.class, master.getId());
master.change(newName);
master = em.merge(master);
return master;
}
[Updated on: Fri, 22 January 2010 17:56] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03746 seconds