javamicrostream

Microstream lazyloading/relationship


following this code https://github.com/microstream-one/demo-readmecorp/tree/master/core/src/main/java/com/jetstreamdb/demo/readmecorp I can see that one book has only one Author, means one author can have many book = one to many relationship

trying to make a book has many Author i tried to do it like in BookShop. (I guess it will be manytomany)

changing

private final Author author;

to

private final Lazy<List<Author>> author;

in constructor I changed to

this.author = Lazy.Reference(author);

and method author() to

public Collection<Author> author()
    {
        return this.author.get();
    }

I also commented out methods in ReadMeCorpData to quickly test then i got this error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.jetstreamdb.demo.readmecorp.Main.main(Main.java:30)
Caused by: java.lang.RuntimeException: Incompatible types: com.jetstreamdb.demo.readmecorp.Author -> one.microstream.persistence.lazy.Lazy

So my question is how can I make one book has many author, may be my thinking is outdated in microstream then where or how can i get ideas to model the data in correct way in microstream?

(I tried to let Author implements Lazy and the error is gone, but since i havent found any example code which implements Lazy I dont know if its ok to do so)


Solution

  • You can use another example with lazy

    https://github.com/microstream-one/example-android-recyclerview/blob/master/app/src/main/java/one/microstream/android/data/CustomerRepository.java