The database I am working on has a multi-tenant design. I want to implement hibernate search on my application however I want hibernate search to index a certain tenant only. How do I achieve that?
You should be able to use dynamic sharding - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#advanced-features-dynamic-sharding
This allows you to split (shard) the data into several Lucene indexes. Using dynamic sharding you can route the data at index and query time using a custom ShardIdentifierProvider. This requires of course that in the implementation you have access to the tenant id, for example via a ThreadLocal.
Related
I am new to spring framework recent i have made small project on microservices, where i create two microservices
department service
User service
I need to know how can i use join in them, i have create one common field in both the service i.e departmentId,
when i use getmapping in user service containing department id fetching the data from department service in respective to that departmentId.
Using intellij, mongodb as database, spring framework,java
Since mongo is a document store type database.
It depends on how the data will be used. You'll need to think how the data will be queried, what will the response may be.
In a RDBMS, it is natural to denormalize your data and split it over several tables and use joins to create the views you need.
In a document store you do exactly the opposite you'll normalize your data and try to include as much as you can to satisfy most queries in one query.
When you use spring, you might also like to use https://spring.io/projects/spring-data-mongodb
If you want to gain in-depth knowledge on mongo, they have several courses available where they can teach you for free: https://university.mongodb.com/
I have an Entity that right now it's stored on my database via Hibernate.
I'd like to remove it from database (as i'm not interested to relate it with other data, or to make some query) and i'd like to persist it on EHCache and dump all data on file ones a day.
I was wondering if i could do that without having an entity linked to database table.
What is your experience?
Unfortunately, it can't work the way you expect it to work.
Hibernate stores a dehydrated entity representation, so using the EHcache data directly will require you to implement a hydration/dehydration processing logic.
If you plan on porting to a non-standard data store, like using a persistent cache as a database, you need more control than Hibernate offers you.
I would try to replace Hibernate 2nd level cache with a service-layer caching implementation (e.g. Spring or even your custom caching abstraction layer). This way you control how the data is going to be serialized/deserialized.
But this is a significant amount of work, so I suggest you take a look on Redis.
I'm using the mongodb-customer-service-data examples (available at https://github.com/SpringSource/spring-data-document-examples).
The example uses #RelatedDocument to associate domain objects across databases. It allows storing and updating objects well enough.
However, I want to do a Query that has Criteria against both the JPA database (in the example HSQLDB) and MongoDB.
Is this even possible? Is there any example anywhere that proves that it is possible?
Comments not directly related to the issue:
My use case is that our application is an Oracle DB, but we are now starting to receive semi-structured data. The JPA Entities are filterable by a user within certain constraints, but we'd like to expand this capability to the semi-structured data.
There also seems to be competing technologies QueryDSL and EclipseLink, but I can't find anything about doing queries across databases.
In JPA, it doesn't appear to be possible to do cross database queries because there are different PersistanceUnits that are associated with each database. However, mongodb cross-store seems to negate this particular problem.
I never used Spring Data JPA, but if JPA isn't capable of doing this I doubt that Spring Data will offer such capabilities.
I don't know what you understand by mongodb cross-store. So I'll explain shortly what mongodb can and can't do.
With mongodb you can't have queries across multiple collections (tables), so you can't do join with plain mongodb. So #RelatedDocument is a feature which Spring Data offers. Related documents may be either embedded (don't know if Spring Data supports this) or may be some simple DBRef to a document within a different collection (and database). With DBRef you can only query on #RelatedDocument fields like _id, collection and database, but none of the actual referenced documents property.
This said mongodb doesn't allow to search cross database in a single query, as you can't do queries across collections so you can't do this against databases either. The only cross-store functionality you have, is for sharded collections. With this you have you collection distributed across multiple nodes through a shardkey. MongoDB may need to query across all collection shards to fulfill your query. But beside this, what I wouldn't call actually a cross-database function, you have no such capabilities.
If this doesn't help, please explain in more detail what you want todo.
We're trying to add search functionality to our application. The search will be over customer data in a multi-tenant application. We need to be careful to make search people can't see or search for other people's data.
Spring Roo allows you to have an entity be searchable. Is there a way to limit the scope of the results to a particular customer id/name?
The project lead asked specifically if there was a way to divide it so each customer had their own index (segment?) in Solr. Has anyone tried this?
Thank you!
As long as you're not giving users unfettered access to the solr interface, I would think that a simple fq (filter query) would work. You would do something like &fq=customerid:1234.
Alternatively, if you need actual separation between the indexes, you can use solr cores, but these have to be configured independently.
Our's is a product specific to a domain.Here are some of the typical security use cases,
A normal User can edit only his profile data or anybody data based on permission
A user can see only data that belongs to his department while another user can data from all departments
These requirements changes from customer to customer so we can not just hard code the filtering logic in our application code or maintain multiple versions of the application.
We use Hibernate criteria based filtering and like to add additional Restrictions based on some expressions associated with a Permission. An expression for use case 1, mentioned above, may look like this, 'userId=user.userId' where 'user' is a keyword and represents current authenticated user and 'userId' is a property of the object for which criteria is created.
We want to define a dsl using which we can derive criteria restriction as well as 'where' clause for sql.
Are there any existing frameworks which will enable us to do it, without going for dsl? Based on the use cases mentioned above, do you think it can be achieved in different way?
Additional Info: We define only domain objects with some meta information to generate UI. Persistence, security etc are taken care by our core framework.
Have you tested Hibernate filters?
They are great mechanism for record level filtering, you can define multiple filters (for example two filters for your case) on each entity and enable or disable them according to current user.
Shall mention that filters can accept parameters (for example your current user id).
We have used this great feature of Hibernate 3 on a large project, which had a hierarchical organization unit and that worked fine.
By the way if you use Oracle as your database, consider Oracle's virtual private database feature.
We decided to go with our own dsl using antlr