# @ProjectionConstructor mapping issue - showing NULL for all fields

**URL:** <https://discourse.hibernate.org/t/projectionconstructor-mapping-issue-showing-null-for-all-fields/9237>\
**Category:** Hibernate Search\
**Created:** [March 21, 2024, 8:43am UTC](https://discourse.hibernate.org/t/projectionconstructor-mapping-issue-showing-null-for-all-fields/9237 "2024-03-21T08:43:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asim\_Hussain](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/asim_hussain/32/3085_2.png) [@Asim\_Hussain](https://discourse.hibernate.org/u/Asim_Hussain)\
**Post date:** [March 21, 2024, 8:43am UTC](https://discourse.hibernate.org/t/projectionconstructor-mapping-issue-showing-null-for-all-fields/9237/1 "2024-03-21T08:43:14Z")

</div>

I’m using Hibernate Search 7.1.0. I am trying to use @ProjectionConstructor. I created a Project class like so:

```auto
@Getter
@Setter
@NoArgsConstructor
public class MyStoryProjection implements Serializable {
	
	private static final long serialVersionUID = 6006691858705971630L;
	private Long id;
	private String title;
	private String city;
	private String name;
	private String url;
	private String belief;
	private String country;
	
	@ProjectionConstructor 
	public MyStoryProjection(
	        @IdProjection Long id, 
	        String title,
	        String city,
	        String name,
	        String url,
	        String belief,
	        String country) {}
}

```

I have a search query like so:

```auto
public List<MyStoryProjection> searchSummaryPhrase(String searchParam, Integer offset, Integer recordsPerPage) {

		searchSession = Search.session(entityManager);
		List<MyStoryProjection> hits = searchSession.search( Story.class )
			.select( MyStoryProjection.class )
	        .where( f -> f.phrase().field( "story")
	                .matching( searchParam )
	        .slop( 1 ))
	        .fetchHits(offset, recordsPerPage);
	log.debug("we got the hits OK");
	return hits;
	}

```

However I get NULL’s for each field in the resulting projection even though it finds a record:

```auto
{
    "myStoryProjections": [
        {
            "id": null,
            "title": null,
            "city": null,
            "name": null,
            "url": null,
            "belief": null,
            "country": null
        }
    ],
    "numRecords": 1,
    "stories": null
}

```

If I use the composite method for searching, it works. Composite method:

```auto
		List<MyStoryProjection> hits = searchSession.search( Story.class )
	        .select( f -> f.composite( 
	        		//StorySummaryProjectionVO::new, 
	                f.field( "title", String.class ), 
	                f.field( "city", String.class ),
	                f.field( "name", String.class ),
	                f.field( "url", String.class ),
	                f.field( "belief", String.class ),
	                f.field( "country", String.class )
	        ) )

```

Any idea why my projection is not working? I don’t even get an error in the stacktrace. Should I up the logging for a particular module? Help. Thanks.

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [March 21, 2024, 8:48am UTC](https://discourse.hibernate.org/t/projectionconstructor-mapping-issue-showing-null-for-all-fields/9237/2 "2024-03-21T08:48:19Z")

</div>

Hello.

The problem is in your constructor:

```auto
	@ProjectionConstructor 
	public MyStoryProjection(
	        @IdProjection Long id, 
	        String title,
	        String city,
	        String name,
	        String url,
	        String belief,
	        String country) {
		// MISSING STUFF HERE!
	}

```

You just ignored the arguments… you need to assign them to your fields.

Or, if you’re on JDK 17+, use a `record`. It’s simpler and shorter, and IMO just better than lombok for immutable classes.  
See the first example in [https://docs.jboss.org/hibernate/stable/search/reference/en-US/html\_single/#mapper-orm-mapping-projection-basics](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-mapping-projection-basics)
