Skip to content

Instantly share code, notes, and snippets.

@DavideD
Forked from gunnarmorling/4.1.0.Beta3.md
Last active August 29, 2015 14:02
Show Gist options
  • Save DavideD/4287ab4c7bace7f21b9d to your computer and use it in GitHub Desktop.
Save DavideD/4287ab4c7bace7f21b9d to your computer and use it in GitHub Desktop.

Hibernate OGM 4.1.0.Beta4 is out, bringing MongoDB improved native query support

This release improve the existing support to MongoDB native queries. In Neo4j, it fixes a bug related to the way we store embedded collection (OGM-49) and reduce the amount of relationships created.

As always, you can either download a release bundle from SourceForge or retrieve the JARs from the JBoss Nexus repository server using Maven, Gradle etc. The GAV coordinates are:

_org.hibernate.ogm:hibernate-ogm-core:4.1.0.Beta4_ for the OGM engine and
_org.hibernate.ogm:hibernate-ogm-<datastore>:4.1.0.Beta4_, depending on the backend you want to use.

Support for MongoDB CLI syntax

It is now possible to specify queries using the MongoDB CLI syntax as shown in the following example:

We now take advantage of labels - a new feature of Neo4J 2.x - to map entities in a more natural way. We use these labels to tag all the nodes belonging to one entity type. This does not only remove the need to put additional properties to the nodes but also will allow us to query for all the nodes of one entity type in an efficient manner.

We also support the execution of native Cypher queries now. You can either create them ad-hoc via EntityManager#createNativeQuery() or using the @NamedNativeQuery annotation on your entities:

String query3 = "db.WILDE_POEM.find(" +
    "{ '$query' : { 'name' : 'Athanasia' }, '$orderby' : { 'name' : 1 } }" +
    "{ 'name' : 1 }" +
    ")";

EntityManager em = ...
List<Object[]> poemNames = (List<Object[]>)em.createNativeQuery( query3 ).getResultList();

Specifying native MongoDB queries using the CLI syntax is an EXPERIMENTAL feature for the time being. Currently only find() and count() queries are supported via the CLI syntax. Further query types (including updating queries) may be supported in future revisions.

More natural mapping for Neo4j associations

In Neo4j, it is possible to navigate a relationship in both directions. We now take advantage of this by creating only one relationship (instead of two) to map both bidirectional and unidirectional associations.

What's next?

For the Neo4j backend, we plan to improve the mapping for one-to-one relationships, remove redundant properties and translate JP-QL queries into native Cypher queries.

We will also work on the generation of (https://hibernate.atlassian.net/browse/OGM-465)[error reports with the failed operations on non transactional db].

You're very welcome to raise your voice on the mailing list, ask questions in the forum or report any bugs or feature requests in the issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment