microstream-one / examples

10 stars 4 forks source link

[ERROR] TypeCastException in Vaadin Application #24

Closed JustinVoitel closed 3 years ago

JustinVoitel commented 3 years ago

Iam trying to integrate Microstream into a vaadin application but after Instantiating the database and running it again I constantly get this error printed: image My DataRoot object looks like this:

public class DataRoot {

   private String name = "test123";
   private ArrayList<String> names = new ArrayList<>();

   public DataRoot() {
      super();
   }

   public ArrayList<String> getNames() {
      return names;
   }

   public void setNames(ArrayList<String> names) {
      this.names = names;
   }

   @Override
   public String toString() {
      return "Root: " + this.name + ", names size: " + this.names.size();
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
}

But I think this is not the troublemaker. Is it maybe, because the underrlying devserver runs with springboot and it cannot cast back the stored root object ?

Steps to recreate

  1. download example vaadin application from (https://start.vaadin.com/?preset=latest)
  2. copy DataRoot class from above
  3. in AboutView.java add:

    ...
    public AboutView() {
        root = new DataRoot();
        sm = EmbeddedStorage.start(root, Paths.get("/etc/microstream/testapp"));
    
        System.out.println(root);
    
        root.setName("newly set name 123");
    
        sm.storeRoot();
    }
    ...
  4. run dev server with:
    mvn spring-boot:run
  5. navigate to /about
  6. stop dev server
  7. restart devserver with:
    mvn spring-boot:run

    Maybe iam doing something wrong or there is still something missing, but help would be appreciated :)

Running on Ubuntu 20.04 using openjdk version "11.0.9.1" 2020-11-04

zdenek-jonas commented 3 years ago

In this case, the program runs in the tomcat application server. You need to pass an instance of the tomcat class loader to Microstream.

so instead of:

sm = EmbeddedStorage.start(root, Paths.get("/etc/microstream/testapp"));
sm = EmbeddedStorage.Foundation(Paths.get("/etc/microstream/testapp"))
                .onConnectionFoundation(cf -> cf.setClassLoaderProvider(
                        ClassLoaderProvider.New(Thread.currentThread().getContextClassLoader())
                ))
                .start(root);

https://manual.docs.microstream.one/data-store/configuration

JustinVoitel commented 3 years ago

Thanks for the fast response 👍It is now working as expected!