MongoDB projection difference between 5.3 and 5.4


#1

We have some code written using OGM 5.3 that does not work in 5.4. A good example can be found in your tests at [1]. In OGM 5.3 createNativeQuery will allow you to specify a query string with projection and a class (ex. EntityManager.createNativeQuery(“db.Movie.find( {}, { ‘year’ : 1, ‘author’ : 1 } )”, Movie.class). In OGM 5.4 an error is now returned saying that project and addEntity are not allowed together. Is this something that can be fixed?

[1] https://github.com/hibernate/hibernate-ogm/blob/5.4.0.Final/mongodb/src/test/java/org/hibernate/ogm/datastore/mongodb/test/query/nativequery/MongoDBProjectionTest.java


#2

The reason we don’t allow that behavior is that it might lead to entities where not all the fields are initialized and this can cause issues when running subsequent queries. This is the related JIRA: https://hibernate.atlassian.net/browse/OGM-1375

Could you give us more information about your use case, please? What kind of queries are you running?
Thanks