Hibernate Search Configuration Help - java

I am trying to configure hibernate search for my application by reading several web tutorials, the majority uses annotation but I uses xml mapping, also, many tutorial are saying to use spring and maven while I don't uses these.
Can someone help and provide some starting point for configuring hibernate search, many web tutorial are not working for me
The application is a gwt application using gilead with hibernate on the back end

As pointed out in the previous answer, Hibernate Search does not have a xml configuration. You can configure Hibernate via xml, but not Search. Since Hibernate Search 3.3 there is an alternative, however, which is the programmatic configuration api - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#hsearch-mapping-programmaticapi
There is an object called SearchMapping. Once instantiated it offers an fluent API to configure Search the same way you would do with annotations. Add the configured SearchMapping instance to your Hibernate Configuration instance using the key *hibernate.search.model_mapping* and Search will automatically bootstrap together with Hibernate Core. There is not much to it. You don't need Spring.
Once Search is running you probably want to write a few lines of code to index your existing database. There is code for that in the online manual.
Last, but not least you need some searches. Have a look how to create a FulltextQuery. Your system probably gets some sort of search input in what for so ever. Your task is to transform the search input from the "frontend" into a Lucene query which you can then pass to Search in order to execute the search and return managed objects.
Last, but not least - maven is a completely different thing. Now we are talking build systems. Using maven you can get automatically download the artifacts from the JBoss Maven repository. However, there are also dist bundles on SourceForge is this is more what you are after. Check http://www.hibernate.org/subprojects/search/download for Search download information.
Hope this helps.

http://docs.jboss.org/hibernate/search/3.3/reference/en-US/html_single/#d0e43
Hibernate Search, however, has itself its own set of annotations (#Indexed, #DocumentId, #Field,...) for which there exists so far no alternative configuration.
I also remember seeing something like this in "Hibernate Search in Action", where the author said that there's not much demand for non-annotation configuration (I don't have my copy now, so, I may be wrong). I guess that there is still not enough demand.
Note that Hibernate itself can be configured via XML, and I assume that you can mix both (XML for Hibernate mappings, annotations for Hibernate Search mappings).

Related

OSGI Equinox with Hibernate JPA Setting up

I am setting up a simple example to persist one Person entity using Hibenate in an OSGI Equinox using eclipse. I read the official documentation in Hibernate web site but the examples use another frameworks and I dont know how many bundles I need and how to set up them.
After a few days trying to use hibernate in an Equinox Osgi, I get it. I created a thread in the Hibernate Forum so you can go there:
https://forum.hibernate.org/viewtopic.php?f=1&t=1029974&p=2473673#p2473673
Basically you need to do step by step, setting up every bundle that you need, and also updated to the Hibernate 4.3.0 version and take care with the order of your bundles in run time!!

Hibernate Search with Apache Lucene

I have a problems with my hibernate search.
I already included the jar file needed however, I don't know how to call the hibernate search annotation and if I needed to create another XML file for the hibernate search.
And also, how can I use this Hibernate Search, what are the cons and pros of this plugins and can you give me any reference like a tutorials on how can I use this. BTW, I'm also using Apache Lucene. It seems that both of this need to be present on my workstation to be able to use the Hibernate Search. I've looked up in Mr.G(google) but can't find a good tutorials that I can truly understand. thanks :)
You have to add properties in you hibernate.cfg.xml file for hibernate.search.default.directory_provider and hibernate.search.default.indexBase
You can refer to this link which gives you idea...

OpenJPA: Code to build entities automatically from DB

Hi I'm looking for a code/tool to generate entities automatically. I'm not looking for a software like eclipselink which has to be executed manually, but rather a piece of code (or a maven plugin) that can be automatically run whenever the db changes. (If I can autorun eclipselink via cron job, that would work for me.)
Some other options:
I think Hibernate offers a reverse engineering method that can be called from maven build that auto generates the entities from db schemas. Does anyone has a such a tool for openjpa.
Any command line utility where you just specify the db urls and options and the utility generates the entities. I can just write a cron to run the utility nightly etc.
Any software that can be called automatically via cron, and it generates the entity will also do.
Update:
OpenJPA Reverse mapping tool seems to really suck at generating a proper entity with annotations, mapping and so on... I would be glad if someone corrected me
Check out Reverse Mapping in the user manual. You can launch that from an ant task.
I doubt a fully automatized tool like that can exist — simply because it can't be done well without human intervention. How would, for example, the algorithm decide which attributes should be taken into account in equals() and hashCode()? Or new relations uni- or bidirectional? Lazy/eager loading? And so on.
As you know, and others have noted, the tools per se exist, but they're rather intended to run once, tweak the result, and work with it from now on, rather than be a part of a continous integration process.

hibernate search without database

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.

How to generate JPA mapping file from the JPA annotated entity classes?

I am using openjpa runtime of JPA specification.
At development time I am using annotations to configure jpa entities.
At Integration, Pre-Production and and Production environment, I am using orm mapping files to configure entities. Please suggest a tool which can generate mapping files from jpa annotations, so that these mapping files can be manually edited for different environment.
If there is already a opensource maven-plugin; will be great.
I don't really know OpenJPA so there is maybe a better way to do this but one option would be to first generate the XML schema file from annotated entities using the Schema Tool and then the orm.xml file from the schema.xml using the Reverse Mapping Tool. Actually, this process is discussed in this thread.
I've checked the OpenJPA Maven Plugin but it doesn't seem to support the Reverse Mapping part (it only has a openjpa:schema goal that allows to Create a file which contains the schema mapping XML, the first required operation, but nothing for the second part). Extending the plugin to add the missing openjpa:reverse-mapping goal would thus require some development but it shouldn't be an hard task.
There is another option though. OpenJPA provides the following Ant tasks for both operations:
org.apache.openjpa.jdbc.ant.ReverseMappingToolTask
org.apache.openjpa.jdbc.ant.SchemaToolTask
So it should be possible to call them from Maven using the Maven AntRun Plugin. Check the documentation for more details on how to use them.

Categories

Resources