質問

Is it possible to use hibernate search features without using hibernate core for the database stuff?

I want to create a Bean with standard Hibernate-Search annotations and store everything by hand for testing purposes (and I don't want to create the Hibernate Tables for testing).

For a class to be annotated with @Indexed I need it to be an @Entity, but because of that I get an error because I didn't specify my database stuff for this class.

My Question is:

How do I use Hibernate Search only for the Lucene management?

役に立ちましたか?

解決

I think the question is here what is your ultimate goal? Do you want to use Hibernate Search in production w/o Hibernate ORM or are you just looking for some testing solutions?

You can actually use Hibernate Search standalone w/o Hibernate ORM. However, you would have to implement several SPI contracts. It's cumbersome, but possible. In fact Infinispan Query (the query capabilities of Infinispan - https://github.com/infinispan/infinispan/tree/master/query) does exactly that. It uses the engine of Hibernate Search w/o the ORM parts. The Search team is on the process to make it much easier to use Search without ORM. Keep an eye on upcoming releases.

If you are just looking for some way to test Hibernate Search + ORM, then you are much better off to use an in memory database. That is the easiest way to do unit testing in this case.

他のヒント

Ultimately your hibernate needs to know the database configurations.. When you notice the hibernate log, Hibernate engine will first register types and as second step it will look for hibernate configuration properties and it will parse and validate in next steps.. My point here is hibernate must have be informed database information... By the way you can also post your error details for further assistance..

Cheeers!

If everything else fails, you can use one of in-memory databases. They will self-destruct after you run your test.

That's how its done (if you have a database, but you don't want to store the indexed stuff into it):

Create a dummy Entity class with all the information you need and do it like this (Example from my code with a Suggest class)

        Transaction tx = fullTextSession.beginTransaction();

        fullTextSession.purgeAll(Suggest.class);

        SuggestionFinder suggestionFinder = context
                .getBean(SuggestionFinder.class);
        List<Suggest> toDelete = new ArrayList<>();
        int i = 0;
        for (Suggest sugg : suggestionFinder.findSuggestionsForIndex()) {
            fullTextSession.save(sugg);
            toDelete.add(sugg);
            fullTextSession.index(sugg);
            if (i++ % 1000 == 0) {
                fullTextSession.flushToIndexes();
                for (Suggest cur : toDelete) {
                    fullTextSession.delete(cur);
                }
                toDelete.clear();
            }
        }
        fullTextSession.flushToIndexes();
        for (Suggest cur : toDelete) {
            fullTextSession.delete(cur);
        }
        toDelete.clear();

        fullTextSession.getSearchFactory().optimize(Suggest.class);

        tx.commit();

EDIT:

I have implemented a Hibernate-Search Standalone version:

https://github.com/Hotware/Hibernate-Search-JPA/tree/master/hibernate-search-standalone

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top