Uploaded image for project: 'Hibernate OGM'
  1. OGM-1416

org.hibernate.PropertyAccessException with MongoDB Native Query. Null assigned to primitve

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.4.0.Alpha1, 5.3.1.Final
    • Component/s: None
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      When a primitive type is used for an Entity field, performing a partial Entity MongoDB native query could lead to an org.hibernate.PropertyAccessException.
      It happens when the primitive field type is not included in the Projection set of the partial query.

      @Entity
      public class OscarWildePoem {
              @Id
      	private Long id;
      	private String name;
      	private String author;
      	private byte rating;
      }
      
      @Test
      	public void nativeQueryProjectionExcludingPrimitive() {
      		final String nativeQuery = "db.WILDE_POEM.find({ 'name' : 'Portia' }, { 'author' : 1, 'copiesSold' : 1 } )";
      
      		inTransaction( session -> {
      			Query query = session.createNativeQuery( nativeQuery ).addEntity( OscarWildePoem.class );
      			OscarWildePoem result = (OscarWildePoem) query.uniqueResult();
      
      			assertThat( result.getId() ).isEqualTo( new Long( 1l ) );
      			assertThat( result.getName() ).isNull();
      			assertThat( result.getAuthor() ).isEqualTo( portia.getAuthor() );
      			assertTrue( result.getRating() == 0 );
      			assertThat( result.getCopiesSold() ).isEqualTo( portia.getCopiesSold() );
      		} );
      	}
      

      Exception mesage:

      org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of org.hibernate.ogm.datastore.mongodb.test.query.nativequery.OscarWildePoem.rating
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: