From cb4005f539af591df85a6feddab99bba88f49ec9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 9 Dec 2025 10:44:50 +0100 Subject: [PATCH] retrospectively mark operations @Incubating New API operations should generally be marked @Incubating, especially when they occur on prominent interfaces like Session, Query, or SessionFactory. These ones weren't. (Sometimes we forget.) And there was a reason they should have been: their signatures are not type safe, featuring an unbound type parameter in the return type, even though their type argument is reified internally. So a RootGraph can masquerade as a RootGraph. This is a big antipattern that I've been trying to systematically root out throughout the whole codebase. --- .../src/main/java/org/hibernate/SessionFactory.java | 2 ++ .../src/main/java/org/hibernate/graph/GraphParser.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java index c03e63bd2ad7..a90a43719c6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java @@ -543,6 +543,7 @@ default RootGraph parseEntityGraph(Class rootEntityClass, CharSequence * * @since 7.0 */ + @Incubating default RootGraph parseEntityGraph(String rootEntityName, CharSequence graphText) { return GraphParser.parse( rootEntityName, graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); } @@ -560,6 +561,7 @@ default RootGraph parseEntityGraph(String rootEntityName, CharSequence gr * * @since 7.0 */ + @Incubating default RootGraph parseEntityGraph(CharSequence graphText) { return GraphParser.parse( graphText.toString(), unwrap( SessionFactoryImplementor.class ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java b/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java index 0bfcb46624ad..3b80690c6749 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/GraphParser.java @@ -9,6 +9,7 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Subgraph; +import org.hibernate.Incubating; import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; @@ -89,6 +90,7 @@ public static RootGraph parse( * * @since 7.0 */ + @Incubating public static RootGraph parse( final String rootEntityName, final CharSequence graphText, @@ -117,7 +119,8 @@ public static RootGraph parse( * * @since 7.0 */ - public static RootGraph parse( + @Incubating + public static RootGraph parse( final CharSequence graphText, final SessionFactory sessionFactory) { if ( graphText == null ) {