Persisting 3rd party entities in browser storage with JPA - java

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.

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.

Related

Can I have multiple data sources in spring without specifying the primary one?

The situation is as follows.
I have a microservice that imports a module. I want that module to be reusable by other microservices and to have it's own data source.
I managed to do this by manually configuring the data source in the module (in a #Config glass), but if I want to import the module, I also have to manually configure my data source in each micro service and specify that it's the primary one.
Is there any way to only configure the module's data base and to let spring do it's automatic config inside the microservices? Thanks, any help is appreaciated.

Correct file path for Hibernate entities and repositories

Currently I am working on a Spring Hibernate project where I created Hibernate entities Company.java, Group.java, Host.java
I have grouped them in a folder called Entities.
I am also using Spring data repository interfaces for those entities. Currently, the names are CompanyRepository.java, GroupRepository.java, HostRepository.java (Not sure if this the correct name scheme).
Should those repositories be in the same folder as the entities or should I create a new folder for any Spring data repository?
Thanks.
The package of your repositories can be anything you want, either the same as your Entities or not. There is no obligation to do one over the other.
That being said, it would be probably be more convenient to have them under their own package

Spring MVC: correct package for POJO used in services

I am developing an MVC application on Spring Boot, here is the structure of its packages:
Package 'domain' contains JPA entities and POJOs for Redis; package "repository" contains Spring Data repositories to work with domain model; package "services" contains service-layer and works with repositories; package "controller" contains REST controllers working with services.
But usually, services need to use some POJOs for service-specific data and pass it to controller. For example, the class FeedPage, which essentially POJO, aggregates the data, calculated FeedService and is not related to the database.
Could you please assist a right package for such POJOs:
1) Store it in "domain" along with DB entites
2) Store it in services package ( services.feed)?
3) Create package "model" under each service and store POJOs there
Thanks!
Stumbled upon my old question.
Ended up adding a DOs classes into corresponding packages in the service layer where it's necessary. A naming convention for the DOs is xxxDO which let me easily notice such classes in a project tree.
Create a folder called model under core. and use them for Data Transfer. These are POJOs are invariably named DTO or Data Transfer objects and would be best in their own package like model. There was a practice in SOA to have the data transfer objects in service specific folder but nowadays with Spring and package based AOP definition possibility, It would be better to have a seperate package for them.

How do I properly set up cross-store persistence using Spring Data JPA + Neo4j?

I am trying to get a very minimal JPA + SDN (Spring Data Neo4j) cross store project running and am trying to demonstrate that saving a partial entity using a JPA repository call will create a corresponding node in Neo4j.
I have followed the instructions / advice that I have been able to find on SO, Google and Spring's site but am currently still having trouble standing things up. I currently have a minimal test project created at:
https://github.com/simon-lam/sdn-cross-store-poc
The project uses Spring Boot and has a simple domain containing a graph entity, GraphNodeEntity.java, and a partial entity, PartialEntity.java. I have written a very basic test, PartialEntityRepositoryTest.java, to do a save on the partial entity and am seeing:
The wrong transaction manager seems to be used because the CrossStoreNeo4jConfiguration class does not properly autowire entityManagerFactory, it is null
As a result of the above ^, no ID is assigned to my entity
I do not see any SDN activity in the logs at all
Am I doing something glaringly wrong?
More generally, I was hoping to confirm some assumptions and better understand cross store persistence support in general:
To enable it, do I need to enable advanced mapping?
As part of enabling advanced mapping, I need to set up AspectJ; does this include enabling load time weaving? If so is this accomplished through using the #EnableLoadTimeWeaving config?
Assuming that all my configuration is eventually fixed, should I expect to see partial nodes persist in Neo4j when I persist them using a JPA repository? This should be handled by the cross store support which is driven by aspects right?
Thank you for any help that can be offered!
I sent a message to the Neo4j Google Group and got some feedback from Michael Hunger so I'm going to share here:
Turns out the cross store lib has been dormant for a while
JPA repos are not supported, only the EntityManager operations are
The cross store setup was not meant for a remote server and was not tested
So in summary my core understanding / assumptions were off!
Source: https://groups.google.com/forum/#!topic/neo4j/FGI8692AVJQ

Annotations in domain objects in client pull complete hibernate dependencies

I want to share some domain objects between my client and server apps.
Starting with Hibernate 4, the Hibernate annotations were integrated in hibernate-core (used to be a separate jar), see http://in.relation.to/Bloggers/NoMoreHibernateannotationsModule
I would really prefer to stick with annotations (and not switch to xml based mapping).
At the same time I would really like to avoid bundling the hibernate core dependencies with the client (which will be transferred to the user via http through java web start, ideally on every startup).
Do I have to go back to Hibernate 3.x? Are these annotation dependencies needed to run the client or do I just need them to compile the client?
Thanks
You don't need to have the annotations of a class in the classpath to be able to load a class.
That said, a Hibernate entity contains collections and references to other entities. The collections are instances of Hibernate collections, and the references can be Hibernate proxies, if they're lazy-loaded. So if you serialize a Hibernate entity from the server to the client, the client will need the Hibernate jar(s) in its classpath to be able to load them.
If you want to avoid the Hibernate dependency at client-side, you should consider transferring DTOs to the client rather than Hibernate entities.

Categories