Problem with hibernate - persistent context
I have something like Person
, and Address
object(Person
has an Address
and other properties).
I update Address
or other properties in one request. And in another request I'm searching through all persons. But sometimes I can see properties modified and sometimes I cannot.
Just making another request will return me either modified or unmodified properties.
Where's the mistake. I tried to flush everywhere, commit, but without any success. Any idea?
My mapping:
@Entity
@Table(schema="zet",name="phone_number")
public class PhoneNumber {
private String id;
private String number;
private Person person;
private int status;
......
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public开发者_运维知识库 void setPerson(Person person) {
this.person = person;
}
@OneToOne(cascade= { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REFRESH })
@JoinColumn(name="person_id")
public Person getPerson() {
return person;
}
public void setNumber(String number) {
this.number = number;
}
@Column(name="num",unique=true,nullable=false)
public String getNumber() {
return number;
}
public void setId(String id) {
this.id = id;
}
@Id
@Column(name = "id", nullable = false)
public String getId() {
return id;
}
}
This looks like a transaction issue. Are you using Spring as a transaction manager?
To make sure the change is persisted, use:
@Transactional(readOnly = false)
public void persistMyChange(Bean myBean) {
myBeanDao.save(myBean);
}
Transactional is readOnly to false by default, but your service layer may be wrapped in a Transactional with readOnly to true.
Oh I got it, thanks a lot for your(Petr Kozelek) help it's very appreciated. There are caches of session for different databases,different connection providers. And different session was being closed finally.
精彩评论