Hi All,
I've encountered a problem of wrong SQL order in an environment using hibernate and JRun:
- hibernate 3.2.2
- JRun4
- spring 2.0.2
I have entities A and B, and there's an association between them
Code:
@Entity
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "TABLE_A")
public class A implements Serializable {
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "a", cascade = CascadeType.ALL)
public Set<B> getBs() {
return bs;
}
public void setBs(Set<B> bs) {
this.bs = bs;
}
...
}
Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "VI_STB_T")
public class B implements Serializable {
...
private A a;
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "ASSOCIATION", joinColumns = @JoinColumn(name = "B_ID", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "A_ID", referencedColumnName = "ID"))
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
...
}
Say I have an A containing a B. If I remove the B and add a second B, the generated SQL should be in this order after I merge A:
1. delete ASSOCIATION between A and first B
2. delete first B
3. insert second B
4. insert ASSOCIATION between A and second B
I can get the above expected result when using Tomcat 5.
But in Jrun, the SQLs are reversed: 3->4->1->2
This should not bring up any problem if B has no unique constraint.
Unluckily, I've got a unique constraint in B in my case. If I perform the above operation and the unique key of first and second B are the same, I'll get an Exception of violating the unique constraint.
Anyone can help me?
Thank you very much.