# MongoDB projection difference between 5.3 and 5.4

**URL:** <https://discourse.hibernate.org/t/mongodb-projection-difference-between-5-3-and-5-4/1726>\
**Category:** Hibernate OGM\
**Created:** [November 16, 2018, 8:34pm UTC](https://discourse.hibernate.org/t/mongodb-projection-difference-between-5-3-and-5-4/1726 "2018-11-16T20:34:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlmarion](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@dlmarion](https://discourse.hibernate.org/u/dlmarion)\
**Post date:** [November 16, 2018, 8:34pm UTC](https://discourse.hibernate.org/t/mongodb-projection-difference-between-5-3-and-5-4/1726/1 "2018-11-16T20:34:13Z")

</div>

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](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)

---

<div class="post-metadata">

**Author:** ![DavideD](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@DavideD](https://discourse.hibernate.org/u/DavideD)\
**Post date:** [November 21, 2018, 2:10am UTC](https://discourse.hibernate.org/t/mongodb-projection-difference-between-5-3-and-5-4/1726/2 "2018-11-21T02:10:47Z")

</div>

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](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
