Skip to content

Conversation

@gavinking
Copy link
Member

for specifying whether a query flushes or not:

  • replaces FlushModeType in the annotation package

  • much less confusing when applied to a Query

    • what do MANUAL and COMMIT mean for a Query?
    • how is AUTO useful for a Query?
  • also make Query.getHibernateFlushMode() obey its documented semantics by returning the session flush mode instead of null when unset

…ushes or not

- replaces FlushModeType in the annotation package
- much less confusing when applied to a Query
  * what do MANUAL and COMMIT mean for a Query?
  * how is AUTO useful for a Query?

- also make Query.getHibernateFlushMode() obey its
  documented semantics by returning the session
  flush mode instead of null when unset
.setTimeout( namedNativeQuery.timeout() < 0 ? null : namedNativeQuery.timeout() )
.setFetchSize( namedNativeQuery.fetchSize() < 0 ? null : namedNativeQuery.fetchSize() )
.setFlushMode( getFlushMode( namedNativeQuery.flushMode() ) )
.setFlushMode( getFlushMode( namedNativeQuery.flush(), namedNativeQuery.flushMode() ) )

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [NamedNativeQuery.flushMode](1) should be avoided because it has been deprecated.
.setTimeout( namedQuery.timeout() < 0 ? null : namedQuery.timeout() )
.setFetchSize( namedQuery.fetchSize() < 0 ? null : namedQuery.fetchSize() )
.setFlushMode( getFlushMode( namedQuery.flushMode() ) )
.setFlushMode( getFlushMode( namedQuery.flush(), namedQuery.flushMode() ) )

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [NamedQuery.flushMode](1) should be avoided because it has been deprecated.
* to flush, depending on its {@link FlushMode}.
*/
NO_FORCING
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everyone, please take a look at this new thing!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is solely about queries, I'd be more inclined to name this QueryFlushMode or move it into o.h.query. For QueryFlushMode, I'd go with:

enum QueryFlushMode {
    FLUSH,
    SKIP,
    /**
     * Defer to {@link Session#getHibernateFlushMode}
     */
    AUTO
}

I get why you named it as you did. I just find it confusing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. QueryFlushMode is fine by me, it was also my first thought.
  2. You're right, I agree it belongs in o.h.query.
  3. FLUSH is fine.
  4. SKIP I don't find extremely clear though I could live with it.
  5. I don't like AUTO here because it doesn't have the same semantics as FlushMode.AUTO.

@sebersole
Copy link
Member

  • what do MANUAL and COMMIT mean for a Query?

Both of those are pseudonyms for never wrt a Query

  • how is AUTO useful for a Query?

AUTO is actually the default for a Query. Not sure what you are asking there tbh

@sebersole
Copy link
Member

So iiuc this basically adds a whole new enum that just limits the set of values from another enum for use in a specific context.

@gavinking
Copy link
Member Author

gavinking commented Jan 4, 2023

Both of those are pseudonyms for never wrt a Query

Yes of course, I know that, but it's nonobvious to a casual onlooker.

AUTO is actually the default for a Query. Not sure what you are asking there tbh

What I'm saying is there's too many things there and it's hard for the user to pick the right one. If I'm going to set this at the level of a query (rather than at the level of the session, where all of the values are useful) then I'm setting it because I either want to:

  • force a flush, or
  • force it not to flush.

// covariant overrides - CommonQueryContract

@Override
Query<R> setHibernateFlushMode(FlushMode flushMode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is not deprecated? It seems to me the intent here is to replace FlushMode when used in the context of a Query

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could deprecate it if you prefer.

@gavinking
Copy link
Member Author

So iiuc this basically adds a whole new enum that just limits the set of values from another enum for use in a specific context.

It replaces org.hibernate.annotations.FlushModeType, which takes all the values of org.hibernate.FlushMode, and adds an additional value.

@gavinking
Copy link
Member Author

I mean, to clarify, my first draft of this was to just deprecate FlushModeType with no replacement, but then I got to thinking about it and decided that this was nicer.

@Sanne
Copy link
Member

Sanne commented Jan 13, 2023

Should we clarify how and if such new options are affected by the configuration properties?

For example we have property org.hibernate.flushMode, I think at least its documentation should say something about how it interacts with the "query flush modes".

@gavinking
Copy link
Member Author

@Sanne you mean the query hint? That is unaffected by this proposal because it's mostly a JPA thing. When using Hibernate-native APIs we don't need hints.

I think there's also a config property but IIRC it's just a default value for that hint. (And I don't consider it a useful thing.)

This proposal is very much only affecting the native APIs.

@Sanne
Copy link
Member

Sanne commented Jan 13, 2023

I'm referring to the configuration property AvailableSettings#FLUSH_MODE, AFAIK it changes the FlushMode, impacting all Session(s) - I'm not sure what you mean by "mostly a JPA thing"?

If they have no relation that's totally fine, but I think that should be made clear.

@gavinking
Copy link
Member Author

I'm referring to the configuration property AvailableSettings#FLUSH_MODE, AFAIK it changes the FlushMode, impacting all Session(s) - I'm not sure what you mean by "mostly a JPA thing"?

Yeah, OK, you're right, it is actually a session-level setting, not a query hint, even though:

  • it looks like a query hint, since it doesn't satisfy our naming convention for configuration properties, and
  • it's only documented as a query hint.

Actually I think we should deprecate this thing, I don't see how it's useful, and honestly it almost looks like it got there by accident.

If they have no relation that's totally fine, but I think that should be made clear.

This proposal has no relation at all to the session-level flush mode, that's correct.

@gavinking
Copy link
Member Author

Actually I think we should deprecate this thing

#5954

Actually it's fine, as a EntityManager-level JPA hint, which is what it started out as. It just should exist as a Hibernate config property in AvailableSettings.

@gavinking
Copy link
Member Author

gavinking commented Sep 14, 2024

superseded by #8954

@gavinking gavinking closed this Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants