views:

38

answers:

3

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;
    }
}
A: 

Which application do you develop? Web or desktop? Do you use custom cache mechanism?

Petr Kozelek
A: 

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.

Thierry-Dimitri Roy
no spring used..
feiroox
A: 

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.

feiroox