0

I have two application servers and 2 database servers named Xapp Xdbase - Yapp Ydabse. Using hibernate at Xapp and Yapp. I need to synchronize data over webservice. With a simple object graph

@Entity
@Table(name="A_table")
public class A extends PersistentObject 
{
    @Column(name="user")
    private String user;

    @ElementCollection()
    @Enumerated(EnumType.STRING)
    @Column(name="b_column")
    @CollectionTable(name="B_table")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<B> bList= new Arralist<B>();


    /* Here comes getter and setter for user and bList */
}

public enum B {
    One,Two,Three
}

PersistentObject is Serializable and has boilerplate code.

XApp and YApp has these classes.

I create a new A object (lets name it Ainstance) at XApp with a B list including two B objects. Desrialize A and send it to Yapp using a webservice at Yapp. At Yapp, I deserialize incoming A and using a repository, repo.saveOrUpdate(Ainstance); and everything is fine . B_table in Ydbase has 2 records.

Then using old Ainstance at XApp, I add a new B to the list and change the user. Then send A again. It deserializes at Yapp perfectly with 3 B records in bList. But when repo.saveOrUpdate(Ainstance) is called, user change applies to dbase but B_table has 2 records. No errors, nothing.

I tried merging Ainstance @YApp then update without luck. What is the problem with lists? I tried a list with class types and they didn't persist too. What is the mistake?

cilman
  • 1
  • 1

1 Answers1

0

after a bit more reading, found that the answer is "replicate".

replicate() is intended to be used instead of save()/persist() when you need to save an entity with a given identifier despite the fact that identifier of the said entity is configured to be generated.

It's useful when some of the entities (perhaps coming from external systems) have pre-existing identifiers, whereas other entities of the same type need their identifiers to be generated.

says axtavt, @Hibernate: Refresh, Evict, Replicate and Flush

Community
  • 1
  • 1
cilman
  • 1
  • 1