0

my problem is this. ill try to make it simple. I am using spring data jpa +spring boot (hibernate config) with mysql.

I have a class (entity) like this.

public class A {

@EmbeddedId
Aid id;


 @OneToMany(fetch = FetchType.EAGER, mappedBy = "a")
    @OrderBy("order ASC")
    @MapKey(name = "b.bid")
    Map<String, B> b;

//id class
 @Embeddable
    public static class Aid implements Serializable {
        private String agent;
        private String id;
    }

//some other fields/methods

}

here other class

public class B {
    private Integer x;
    private String code;
    @Transient
    private String value;

    //B embedable id class goes here

}

Note you can assume all missing annotations / method / id are there and this is perfectly working code. I did not added those here to avoid being complicate the question.

this is my question.

when I fetch this A object from database I adding it to map [storageMap] and during the program from A object which is in storageMap read and its B objects value field (B object in Map of A object) get update.

but my problem is when i fetch again A from database it give me previously fetched and dirty (modified) object. but I need fresh copy from database to reset all modifications. hibernate does not know its dirty because its @Transient ? how I can solve this. ( I know if I deep copy what return from database before adding to my storageMap would solve the problem. any other better way to do?)

Derek Noble
  • 289
  • 1
  • 3
  • 13
  • if you dont need those entities in the cache you can evict them. Or just clear all the cache – Zeromus May 21 '18 at 00:42
  • my requirement is when that Transient field update (add value to Transient field in this case "value" field) Hibernate to consider this as Dirty and fetch fresh from DB when next time find() called. – Derek Noble May 21 '18 at 01:03

0 Answers0