@ProjectionConstructor mapping issue - showing NULL for all fields

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

@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:

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:

{
    "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:

		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.

Hello.

The problem is in your constructor:

	@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