Hibernate-Search with Lucene without database? [duplicate] - java

Is it possible to use hibernate-search only for it's annotations (bean => document/document => bean mapping), without using a database at all? If so, are there any online samples that show basically how to set this up?
I found the following: http://mojodna.net/2006/10/02/searchable-annotation-driven-indexing-and-searching-with-lucene.html, but I'd prefer hibernate-search if it supports my use case.

Hibernate search 3.4 has decoupled the query engine from Hibernate Core. For instance, Hibernate Search is reused to implement queries with Infinispan. I don't know if the code is packaged so that you could use HS with, let's say Spring and JDBCTemplate (something I would like to do). That's a lead I will investigate later but maybe you can check it out...

Starman is correct, Hibernate Search in version 3.4 is abstracting the search engine from Hibernate Core, and the Infinispan Query is an integration example which works fine without a database. There would be no problems with Spring either, but you'd need to make sure to send update event to the query engine so that the index doesn't get out of synch. When using Hibernate the advantage is that it transparently listens for changes to the database and applies them to the index at transaction commit, so the index is always in synch (or close, if configuring Search to use async backends).
I'd suggest to look into the code of Infinispan Query, as it's very small and just delegating calls to expose an Infinispan flavoured API. Most of the code is tests or integration to properly manage the lifecycle of the engine: start and stop it together with Infinispan.

I don't think that's possible because when you enable Hibernate search you are enabling that on a Entity and that Entity has references to the table and the search index.

Related

Can be Solr-Spring-Data be adapted to the embbeded Lucene?

I'd like to design a portable application that is using Spring with JPA, but doesn't deal with Hibernate to make it possible to easily to port it to Google Apps Engine. In case of data persistence everything can be designed well, while I don't see any "spring data way" to instrument the classes for embedded internal Lucene usage (i.e without using of Solr as external webservice on the different URL). So, i'd like to have the local Lucene embedded into my Spring app (that will make possible to replace it with Luceneappsengune implementation), while having all boilerplate code to be handled on the way it is done with solr-spring-data. Hibernate Search annotations also doesn't work for me in this case. Any thoughts, how to do it?
So in examples I see that the almost the only bean configured is
#Bean
public SolrClient solrClient() {
return new HttpSolrClient("http://localhost:8983/solr");
}
Why don't we have the similar adapter for the internally used Lucene?

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

Spring Roo - Bypass Hibernate

I have a Spring/Roo application which uses PostgreSQL and Hibernate.
As is appropriate, the connection information is located in the database properties file
src/main/resources/META-INF/spring/database.properties
Unfortunately, I have a situation where querying the database through Hibernate is draining the resources too much. I am sure that I can extract the database information (url/username/password) from the file listed above, but I am not sure where to begin my search.
Is there a manual or otherwise where I can find this information?
If you wish to bypass Hibernate to write more efficient queries by hand, you don't have to make separate connections to do it, and should not do so.
Get a Hibernate session and unwrap it to get the underlying java.sql.Connection. Or use native SQL via Hibernate's own interfaces.
That way you still get to use the useful bits of Hibernate, like the connection pooling integration. Sharing the same connection pool as Hibernate will improve efficiency, and you'll have a lot less extra code if you do it this way.
I haven't used Spring Roo, so I can't speak specifically for it. Here's info for Hibernate used via JPA or here. For direct Hibernate usage where you have a Session object, use Session.connection() on old versions of Hibernate, or the Work interface on newer versions:
Session.doWork()
session.connection() deprecated on Hibernate?
How to get jdbc connection from hibernate session?
Alternative of deprecated hibernate getSession().connection()
If you insist on doing this by hand anyway, start with ClassLoader.getResource(...).

Spring Data/JPA Repositories with DynamoDB and MySQL dual datasources

I'm familiar with how to make Spring handle multiple datasources dynamically via multiple persistence-units and multiple entityManagerFactoryBean implementations but what I'm struggling with is how to have a MySQL dialect and a DynamoDB dialect from within the same spring configuration, via spring-config xml files.
The work pattern is as follows:
[data POJO in, from some endpoint] -> Persist POJO into DynamoDB, retrieving the UUID of that object (business key as field on POJO) -> Persist UUID as a compound key (no referential integrity, it's just another column) into MySQL Database [with other related mapped entities].
I'm struggling with quite how on earth to go about adding the DynamoDB instance into the Spring configuration files to achieve this.
For what it's worth, the related repositories are going to be in separate packages.
Any starters for 10 would be gratefully received! I've done some searching but all DynamoDB mapper frameworks seem to be at a much higher level - have I missed something here? I've been looking at Spring-Data DynamoDB but still can't make the link between the configuration file and Dynamo.
Thanks in advance,
A.
========= UPDATE IN THINKING =========
I think I've gone about this the wrong way. From digging around the samples a lot more, doing a local integration test [pure dynamodb], I don't think it's possible to use DynamoDB as part of an EntityManager Factory implementation: to that end, I think I'm going to have to "create" my own repository implementations that call out to the mapper and AWS connection helper classes etc. for Dynamo, rather than using any of the JPA spring-provided code.
Unless anyone can recommend/suggest otherwise?
Question closed - after much investiation the only real way to do it is to introduce ones own interpretation of a repository and DAO-based implementation.
There is one interesting project, however, Spring Data Dynamodb. Looks interesting but not quite ready for Enterprise Production release.

Hibernate Secondary Level Cache

Scenario: Project consists of reference data which is updated once a week. Hence constantly querying this reference data for every transaction from the database is not efficient. Hence the motivation to cache this data.
Question: If secondary level caching and query caching in Hibernate is activated and the cache element in the hibernate configuration is set to read-only, how will hibernate know when to update the cache if a change is made to the database via another program. Is this automatically handled by Hibernate or do we have to clear the cache using some trigger?
If this is handled by Hibernate could someone shed light on how this is handled?
The JBoss documentation was not very clear about the management of the cache.
I am currently using Hibernate 3.6 with Spring 3.1 and do not wish to upgrade to Hibernate 4 if its not necessary.
It wont.
The second level cache expects all access to the data to happen via the ORM framework so if you have another actor in the db your cache will become stale.
You can clear the cache though - see this
code snippet
So you could expose a service that allows the 3rd party to clear the cache on your app when the database gets updated.

Categories