Skip to content

Commit

Permalink
hibernate 6 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Sep 16, 2024
1 parent 1efb6b5 commit 1b7dffa
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.metadata.ClassMetadata;
import jakarta.persistence.metamodel.Metamodel;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -105,20 +105,13 @@ public boolean isTransactionPending() {
return info.getTransaction() != null;
}

/**
* {@inheritDoc}
*/
@Override
public ClassMetadata getMetadata(Object target) {
public Metamodel getMetadata(Object target) {
if (target == null) {
return null;
}

if (target instanceof Class) {
return sessionFactory.getClassMetadata((Class<?>) target);
}

return sessionFactory.getClassMetadata(target.getClass());
return sessionFactory.getMetamodel();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.metadata.ClassMetadata;

import jakarta.persistence.metamodel.Metamodel;

import java.util.Optional;

Expand Down Expand Up @@ -54,29 +55,32 @@ public interface ConnectionManager {

/**
* Check if this connection manager has already been initialized.
* @return true if {@link #initialize()} has been called and the session factory is available.
*
* @return true if {@link #initialize()} has been called and the session
* factory is available.
*/
boolean isInitialized();

/**
* Allow loading hbm.xml files from additional locations.
*
* @param additionalLocation the array of package names to be added to the scan.
* @param additionalLocation the array of package names to be added to the
* scan.
*/
void setAdditionalPackageNames(String[] additionalLocation);

/**
* Set the name for Prometheus Hiberante Statistics collector
*
* @param componentName The component name for collector registration, used for metric label value
* @param componentName The component name for collector registration, used
* for metric label value
*/
void setComponentName(String componentName);

/**
* Returns Hibernate session stored in ThreadLocal storage. If not
* present, creates a new one and stores it in ThreadLocal; creating the
* session also begins a transaction implicitly.
* Returns Hibernate session stored in ThreadLocal storage. If not present,
* creates a new one and stores it in ThreadLocal; creating the session also
* begins a transaction implicitly.
* @return Session asked for
*/
Session getSession();
Expand Down Expand Up @@ -113,7 +117,7 @@ public interface ConnectionManager {
* @param target an object instance or a class to retrieve the metadata for
* @return the {@link ClassMetadata} for the given object.
*/
ClassMetadata getMetadata(Object target);
Metamodel getMetadata(Object target);

/**
* Closes Hibernate Session stored in ThreadLocal storage.
Expand Down
Loading

0 comments on commit 1b7dffa

Please sign in to comment.