HHH-18216 add StatelessSession.getIdentifier()

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-06-02 08:19:34 +02:00
parent 386bb1138a
commit 1a5456dde1
3 changed files with 18 additions and 1 deletions

View File

@ -286,4 +286,15 @@ public interface StatelessSession extends SharedSessionContract {
* @since 6.0
*/
void fetch(Object association);
/**
* Return the identifier value of the given entity, which may be detached.
*
* @param entity a persistent instance associated with this session
*
* @return the identifier
*
* @since 6.6
*/
Object getIdentifier(Object entity);
}

View File

@ -769,6 +769,12 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
}
}
@Override
public Object getIdentifier(Object entity) throws HibernateException {
checkOpen();
return getFactory().getPersistenceUnitUtil().getIdentifier(entity);
}
@Override
public boolean isAutoCloseSessionEnabled() {
return getFactory().getSessionFactoryOptions().isAutoCloseSessionEnabled();

View File

@ -136,7 +136,7 @@ public class LifecycleMethod extends AbstractAnnotatedMethod {
declaration
.append("\t\tif (")
.append(sessionName)
.append(".getFactory().getPersistenceUnitUtil().getIdentifier(")
.append(".getIdentifier(")
.append(iterateParameter ? "_entity" : parameterName)
.append(") == null)\n")
.append("\t\t\t")