This is an automated email from the git hooks/post-receive script. New commit to branch feature/4062 in repository topia. See https://gitlab.nuiton.org/nuiton/topia.git commit 763e62bf270dcde1f3efecc231504bdf8a231b4f Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Dec 15 11:31:52 2016 +0100 refs #4062 Go back to hibernate 5.1.3 to stay on java 7 --- pom.xml | 6 +-- .../internal/AbstractTopiaPersistenceContext.java | 51 +++++++++++----------- .../nuiton/topia/persistence/util/TopiaUtil.java | 21 ++++----- .../migration/AbstractTopiaMigrationCallback.java | 3 +- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/pom.xml b/pom.xml index 6092176..92b277c 100644 --- a/pom.xml +++ b/pom.xml @@ -225,7 +225,7 @@ <h2Version>1.3.176</h2Version> <hamcrestVersion>1.3</hamcrestVersion> - <hibernateVersion>5.2.3.Final</hibernateVersion> + <hibernateVersion>5.1.3.Final</hibernateVersion> <javassistVersion>3.20.0-GA</javassistVersion> <junitVersion>4.12</junitVersion> <liquibaseVersion>3.5.3</liquibaseVersion> @@ -243,8 +243,8 @@ <siteSourcesType>rst</siteSourcesType> <ciViewId>ToPIA</ciViewId> - <javaVersion>1.8</javaVersion> - <signatureArtifactId>java18</signatureArtifactId> + <javaVersion>1.7</javaVersion> + <signatureArtifactId>java17</signatureArtifactId> <signatureVersion>1.0</signatureVersion> </properties> diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java index 3ee00a4..d1785fa 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaPersistenceContext.java @@ -49,7 +49,6 @@ import org.nuiton.topia.persistence.support.TopiaHibernateSupport; import org.nuiton.topia.persistence.support.TopiaJpaSupport; import org.nuiton.topia.persistence.support.TopiaSqlSupport; -import javax.persistence.metamodel.EntityType; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Map; @@ -280,36 +279,36 @@ public abstract class AbstractTopiaPersistenceContext implements TopiaPersistenc SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory(); Preconditions.checkState(hibernateFactory != null, "The Hibernate SessionFactory is null, please initialize"); - boolean found = false; - try { - EntityType<E> entity = hibernateFactory.getMetamodel().entity(entityClass); - found = entity != null; - } catch (Exception e) { - } - if (!found) { - try { - EntityType<Object> entity = hibernateFactory.getMetamodel().entity(entityClass.getName() + "Impl"); - found = entity != null; - } catch (Exception e) { - } - } - if (!found) { - try { - EntityType<Object> entity = hibernateFactory.getMetamodel().entity(entityClass.getName() + "Abstract"); - found = entity != null; - } catch (Exception e) { - } - } - -// if (hibernateFactory.getMetamodel().entity(entityClass) == null && -// hibernateFactory.getMetamodel().entity(entityClass.getName() + "Impl") == null && -// hibernateFactory.getMetamodel().entity(entityClass.getName() + "Abstract") == null) + //TODO Use this code for hibernate >= 5.2 +// boolean found = false; +// try { +// EntityType<E> entity = hibernateFactory.getClassMetadata(entityClass).; +// found = entity != null; +// } catch (Exception e) { +// } +// if (!found) { +// try { +// EntityType<Object> entity = hibernateFactory.getMetamodel().entity(entityClass.getName() + "Impl"); +// found = entity != null; +// } catch (Exception e) { +// } +// } +// if (!found) { +// try { +// EntityType<Object> entity = hibernateFactory.getMetamodel().entity(entityClass.getName() + "Abstract"); +// found = entity != null; +// } catch (Exception e) { +// } +// } + + boolean found = hibernateFactory.getClassMetadata(entityClass.getName() + "Impl") != null + || hibernateFactory.getClassMetadata(entityClass.getName() + "Abstract") != null; if (! found) { if (log.isInfoEnabled()) { String format = "List of supported persistence classes: %s"; - String message = String.format(format, hibernateFactory.getMetamodel().getEntities()); + String message = String.format(format, hibernateFactory.getAllClassMetadata().values()); log.info(message); } String format = "The following entity type %s is not managed by this context, you probably forgot to declare it."; diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java index ae2eccd..5975c05 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaUtil.java @@ -38,10 +38,10 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; -import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Table; +import org.hibernate.resource.transaction.spi.TransactionStatus; import org.nuiton.topia.persistence.SchemaValidationTopiaException; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaException; @@ -301,7 +301,7 @@ public class TopiaUtil { String hbm2ddl = configuration.getProperties().getProperty(AvailableSettings.HBM2DDL_AUTO); if (ImmutableSet.of("update", "create", "create-drop").contains(hbm2ddl)) { log.warn(String.format("Be careful, you are about to let Hibernate automatically create or update " + - "your database schema. [%s=%s]", AvailableSettings.HBM2DDL_AUTO, hbm2ddl)); + "your database schema. [%s=%s]", AvailableSettings.HBM2DDL_AUTO, hbm2ddl)); } } @@ -312,7 +312,7 @@ public class TopiaUtil { * the dealed entities. * * @param configuration hibernate db configuration - * @param metaData hibernate metadata + * @param metaData hibernate metadata * @return {@code true} if there is no schema for any of the dealed entities, * {@code false} otherwise. * @since 2.5.3 @@ -342,7 +342,7 @@ public class TopiaUtil { if (currentTableName.equalsIgnoreCase(testTable.getName())) { if (log.isDebugEnabled()) { log.debug("Existing table found " + testTable.getName() + " for entity " + - persistentClass.getClassName() + ", db is not empty."); + persistentClass.getClassName() + ", db is not empty."); } return false; @@ -393,7 +393,7 @@ public class TopiaUtil { connection = connectionProvider.getConnection(); - for (PersistentClass persistentClass : metadata .getEntityBindings()) { + for (PersistentClass persistentClass : metadata.getEntityBindings()) { Table testTable = persistentClass.getTable(); @@ -404,7 +404,7 @@ public class TopiaUtil { if (currentTableName.equalsIgnoreCase(testTable.getName())) { if (log.isDebugEnabled()) { log.debug("Existing table found " + testTable.getName() + " for entity " + - persistentClass.getClassName() + ", db is not empty."); + persistentClass.getClassName() + ", db is not empty."); } return false; @@ -443,9 +443,9 @@ public class TopiaUtil { public static Map<String, Object> convertPropertiesArrayToMap(Object... propertyNamesAndValues) throws IllegalArgumentException { int propertiesLength = propertyNamesAndValues.length; Preconditions.checkArgument(propertiesLength % 2 == 0, - "Wrong number of argument " - + propertiesLength - + ", you must have even number."); + "Wrong number of argument " + + propertiesLength + + ", you must have even number."); Map<String, Object> properties = new LinkedHashMap<String, Object>(); for (int i = 0; i < propertyNamesAndValues.length; ) { Object aPropertyName = propertyNamesAndValues[i++]; @@ -525,6 +525,7 @@ public class TopiaUtil { /** * Builds a new instance of Hibernate SessionFactory according to the given Hibernate Configuration + * * @param hibernateConfiguration an initialized Hibernate Configuration * @return an instance of SessionFactory */ @@ -577,7 +578,7 @@ public class TopiaUtil { if (log.isErrorEnabled()) { log.error("Exception during Hibernate session usage, rollbacking transaction", eee); } - if (session != null && session.isOpen() && session.getTransaction().isActive()) { + if (session != null && session.isOpen() && TransactionStatus.ACTIVE == session.getTransaction().getStatus()) { session.getTransaction().rollback(); } throw new TopiaException("Exception during Hibernate session usage", eee); diff --git a/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java b/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java index 73f2b76..f166c5d 100644 --- a/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java +++ b/topia-service-migration/src/main/java/org/nuiton/topia/migration/AbstractTopiaMigrationCallback.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; +import org.hibernate.resource.transaction.spi.TransactionStatus; import org.nuiton.topia.migration.mappings.TMSVersionHibernateDao; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.internal.support.HibernateTopiaSqlSupport; @@ -129,7 +130,7 @@ public abstract class AbstractTopiaMigrationCallback { if (log.isDebugEnabled()) { log.error("Exception during schema migration, rollbacking transaction", eee); } - if (session != null && session.isOpen() && session.getTransaction().isActive()) { + if (session != null && session.isOpen() && TransactionStatus.ACTIVE == session.getTransaction().getStatus()) { session.getTransaction().rollback(); } throw new TopiaException("Exception during schema migration", eee); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.