Search code examples
javagwtjpalocal-storageerrai

Persisting 3rd party entities in browser storage with JPA


I have two projects (app.ui & models). models is a dependency in app.ui. There we have all the entity classes. app.ui is an errai project that uses JPA to save objects in the browser's storage.

So, I'm following the documentation in terms of annotations and stuff. If I create a class in app.ui and try to save it locally, it works. But if I have the same class with the exact same annotations in models.jar

java.lang.IllegalArgumentException: com.magick.models.shared.Strategy is not a known entity type
  org.jboss.errai.jpa.client.local.ErraiMetamodel.entity(ErraiMetamodel.java:92)
  org.jboss.errai.jpa.client.local.ErraiMetamodel.entity(ErraiMetamodel.java:108)
  org.jboss.errai.jpa.client.local.ErraiMetamodel.entity(ErraiMetamodel.java:113)
  org.jboss.errai.jpa.client.local.ErraiEntityManager.changeEntityState(ErraiEntityManager.java:180)
  org.jboss.errai.jpa.client.local.ErraiEntityManager.persist(ErraiEntityManager.java:469)
  app.client.local.strategy.StrategyProducer.saveStrategyLocally(StrategyProducer.java:83)
  app.client.local.strategy.StrategyProducer.saveStrategiesInBrowser(StrategyProducer.java:78)
  app.client.local.strategy.StrategyProducer.access$3(StrategyProducer.java:76)
  app.client.local.strategy.StrategyProducer$1$1.callback(StrategyProducer.java:68)
  app.client.local.strategy.StrategyProducer$1$1.callback(StrategyProducer.java:1)

Any ideas?

Thanks in advance.


Solution

  • In order to make this work, the model that needs to be persisted on browser's local storage it should be annotated with @Entity and should reside in the client-side package as errai ignores persistence.xml for errai-jpa-client and scans it in the client side package.

    That is, in the package that GWT compiles.

    Also try to use the browser plugin to check for the contents of local storage.

    Hope this helps.