It’s my great pleasure to announce the release of Hibernate OGM 4.1.0.Beta7! The release brings support for MongoDB’s object id, a clarification of what are our public API/SPI packages as well as several bugfixes and many other improvements.
Use the following GAV coordinates with tools such as Maven, Gradle etc.:
- org.hibernate.ogm:hibernate-ogm-core:4.1.0.Beta7 for the Hibernate OGM engine and
- org.hibernate.ogm:hibernate-ogm-<%DATASTORE%>:4.1.0.Beta7, depending on the backend you want to use.
Alternatively, there is a release bundle containing Hibernate OGM and all its dependencies available for download from SourceForge.
Support for MongoDB’s object id
When talking about Hibernate OGM, one of the most requested features we heard was support for the native object id type in MongoDB. Finally we got around to implementing this feature.
You can map object ids either directly via MongoDB’s org.bson.types.ObjectId type or using a String. The following shows an example:
@Entity
public class GolfPlayer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Type(type = "objectid")
private String id;
// Alternatively, the following could be used:
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private ObjectId id;
private String name;
private double handicap;
//...
}
The @GeneratedValue annotation causes the id to be automatically generated by MongoDB upon insertion of the entity, similar to e.g. AUTO_INCREMENT columns in MySQL. The @Type annotation makes sure the string is mapped as an object id rather than as plain string. So a GolfPlayer document could e.g. look like this:
{
"_id" : ObjectId("542ac33630043ffe5bcb4efa"),
"name" : "Alexis",
"handicap" : 9.7
}
Also related to MongoDB is a nice improvement around JP-QL queries. You can now refer to properties of embeddable objects in your queries:
@Entity
@NamedQuery(name = “PersonsByCity”, query = "FROM Person p WHERE p.address.city = :pCity")
public class Person {
@Id
private ObjectId id;
@Embedded
private Address address;
// ...
}
Here, the named query refers to the city property of the embedded address object.
API/SPI package restructuring
As we’re on our road to the 4.1.0.Final release, we spent a fair amount of time for clearly separating the OGM code base into API, SPI and internal packages. Our goal is to make clear what is supported in the long term and what is not.
API packages (application programming interface) are all those packages which are intended to be accessed by users of Hibernate OGM, i.e. people building applications on top of it. Any package which does not have “spi” or “impl” in its name is an API package. Note that there are only very few API packages in Hibernate OGM. Most of the time you will work with the JPA (javax.persistence.* packages) or the “classic” API from Hibernate ORM.
SPI packages (service provider interface) are packages which contain contracts to be used and/or implemented by authors of custom grid dialects. So if for instance you would write a dialect for your favorite NoSQL store (btw. you should consider to contribute it to OGM), then you would access the SPI packages. They have a “spi” in their name. In order to clearly separate API and SPI, we had to rename several packages and move some types around. So existing custom dialects need to be adapted to this new structure. Good news is that it basically is enough to do a “re-organize imports” in your favorite IDE to adapt to most of the changes. We aim at a stable SPI (and of course API as well) with the 4.1 Final release.
Finally, there are internal packages of the Hibernate OGM engine which are not intended for usage by users nor dialect implementors. You can recognize those by the “impl” in their name. Internal packages and types may be changed, removed etc. without notice. So if you think there is a specific internal type which you need to access, please let us know so we can decide what to do and e.g. promote it to API or SPI.
Please refer to the migration notes to learn more about the package changes in this release.
Useful links
As always we’re very interested in your feedback. Here are some helpful links for you:
So give it a try and let us know how you like this release!