Migrating from Hibernate 5 to 6 results in error that target lists have at most 1664 entries

When migrating from WildFly 26 (Hibernate 5 and JavaEE 8) to WildFly 35 (Hibernate 6 and Jakarta EE 10) I am getting the error below for the same Entity-Model:

target lists can have at most 1664 entries

Hibernate 6 makes a lot of more joins than Hibernate 5 with the same Entity model!

This error is not specific to Postgres because it also occurs with MS SQL Server with a different number of entities.

What’s the reason for this error in Hibernate 6 and where to find relevant documentation?

WildFly 35 uses Hibernate 6.6.3.Final

(post deleted by author)

Probably with some more details I’ll get an answer :wink:

I have a complex entity hierarchy with lots of @ManyToOne and @OneToOne properties and FetchType.EAGER

@Entity
class A {
	// some more @ManyToOne properties
}

@Entity
class B {
	@ManyToOne(fetch = FetchType.EAGER)
	private A a;	

	@ManyToOne(fetch = FetchType.EAGER)
	private B B;

	// some more @ManyToOne properties
}

@Entity
class C {
	@ManyToOne(fetch = FetchType.EAGER)
	private A a;

	@OneToOne(fetch = FetchType.EAGER, optional = true)
	private B b;

	@ManyToOne(fetch = FetchType.EAGER)
	private C C;

	// some more @ManyToOne properties
}

Selecting entities of Class C worked with WildFly 26 and Hibernate 5. But after migrating to WildFly 35 with Hibernate 6 I get the error that target lists can have at most 1664 entries. Reason is, that there are a lot of more joins in Hibernate 6.

Can someone tell me, why Hibernate 6 produces more joins for EAGER properties than Hibernate 5 and where to find relevant documentation?

This is mentioned in the migration guide for 6.0: hibernate-orm/migration-guide.adoc at 6.0 · hibernate/hibernate-orm · GitHub

You can either specify a max fetch depth to reduce the amount of joins or even better, try to get rid of EAGER fetching, because it’s a pain and cripples performance.