fix the signature of Session.merge()

previously Session.merge() erased the generic type parameter
inherited from the supertype, obligating the client code to
perform a typecast
This commit is contained in:
Gavin King 2021-11-26 13:04:37 +01:00 committed by Steve Ebersole
parent 942dd7283f
commit 61cba87096
2 changed files with 6 additions and 6 deletions

View File

@ -479,7 +479,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return an updated persistent instance
*/
Object merge(Object object);
<T> T merge(T object);
/**
* Copy the state of the given object onto the persistent object with the same
@ -497,7 +497,7 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose
*
* @return an updated persistent instance
*/
Object merge(String entityName, Object object);
<T> T merge(String entityName, T object);
/**
* Make a transient instance persistent. This operation cascades to associated

View File

@ -807,15 +807,15 @@ public class SessionImpl
// merge() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public Object merge(String entityName, Object object) throws HibernateException {
public <T> T merge(String entityName, T object) throws HibernateException {
checkOpen();
return fireMerge( new MergeEvent( entityName, object, this ) );
return (T) fireMerge( new MergeEvent( entityName, object, this ) );
}
@Override
public Object merge(Object object) throws HibernateException {
public <T> T merge(T object) throws HibernateException {
checkOpen();
return fireMerge( new MergeEvent( null, object, this ));
return (T) fireMerge( new MergeEvent( null, object, this ));
}
@Override