This current push is in the middle of changes for Hibernate 5.x. Before

going to 6, you are recommended to upgrade to 5 first.
This commit is contained in:
Cyrus 2022-04-19 06:50:13 -04:00
parent d4b6fdd1df
commit 545e5b0918
17 changed files with 66 additions and 57 deletions

View File

@ -1,16 +1,16 @@
package hirs.attestationca;
import org.hibernate.SessionFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import hirs.persist.DBAppraiserManager;
import hirs.persist.DBDeviceGroupManager;
import hirs.persist.DBPolicyManager;
import hirs.persist.PersistenceConfiguration;
import hirs.utils.HIRSProfiles;
import org.hibernate.SessionFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/**
* Simply holds a contextInitialized method which will be called when the web app starts.

View File

@ -29,7 +29,7 @@ import org.springframework.context.annotation.PropertySources;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

View File

@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
/**
* Spring configuration class for persistence beans used by the Attestation CA Portal.

View File

@ -6,7 +6,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;

View File

@ -33,7 +33,7 @@ dependencies {
compile libs.commons_http
compile libs.commons_valid
compile libs.hibernate
compile libs.hikari
// compile libs.hikari
compile libs.jackson
compile libs.jadira_usertype
compile libs.joda_time

View File

@ -1,14 +1,14 @@
package hirs.data.persist;
import java.util.Date;
import java.util.UUID;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import java.util.Date;
import java.util.UUID;
/**
* An abstract database entity.

View File

@ -1,6 +1,9 @@
package hirs.data.persist.type;
import static java.lang.String.format;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.StringType;
import org.hibernate.usertype.UserType;
import java.io.Serializable;
import java.net.InetAddress;
@ -10,10 +13,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Objects;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.type.StringType;
import org.hibernate.usertype.UserType;
import static java.lang.String.format;
/**
@ -95,7 +95,7 @@ public final class InetAddressType implements UserType {
*/
@Override
public Object nullSafeGet(final ResultSet rs, final String[] names,
final SessionImplementor session, final Object owner)
final SharedSessionContractImplementor session, final Object owner)
throws HibernateException, SQLException {
final String ip = (String) StringType.INSTANCE.get(rs, names[0],
session);
@ -122,7 +122,7 @@ public final class InetAddressType implements UserType {
*/
@Override
public void nullSafeSet(final PreparedStatement st, final Object value,
final int index, final SessionImplementor session)
final int index, final SharedSessionContractImplementor session)
throws SQLException {
if (value == null) {
StringType.INSTANCE.set(st, null, index, session);

View File

@ -1,5 +1,10 @@
package hirs.data.persist.type;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
import javax.sql.rowset.serial.SerialBlob;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Serializable;
@ -14,12 +19,6 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.Objects;
import javax.sql.rowset.serial.SerialBlob;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.usertype.UserType;
/**
* This is a class for persisting <code>X509Certificate</code> objects via
@ -100,7 +99,7 @@ public final class X509CertificateType implements UserType {
*/
@Override
public Object nullSafeGet(final ResultSet rs, final String[] names,
final SessionImplementor session, final Object owner)
final SharedSessionContractImplementor session, final Object owner)
throws HibernateException, SQLException {
final Blob cert = rs.getBlob(names[0]);
if (cert == null) {
@ -130,7 +129,7 @@ public final class X509CertificateType implements UserType {
*/
@Override
public void nullSafeSet(final PreparedStatement st, final Object value,
final int index, final SessionImplementor session)
final int index, final SharedSessionContractImplementor session)
throws SQLException {
if (value == null) {
st.setString(index, null);

View File

@ -100,7 +100,9 @@ public final class CSVGenerator {
StringBuilder sb = new StringBuilder();
CSVPrinter csvPrinter;
try {
csvPrinter = CSVFormat.DEFAULT.withRecordSeparator(System.lineSeparator()).print(sb);
csvPrinter = CSVFormat.DEFAULT.builder()
.setRecordSeparator(System.lineSeparator())
.build().print(sb);
for (ImaBlacklistRecord record : blacklistBaseline.getRecords()) {
String digest = "";
Digest hash = record.getHash();

View File

@ -22,7 +22,7 @@ import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -31,6 +31,9 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -162,7 +165,8 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
* @return the configured database implementation
*/
protected DBManager.DBImpl getConfiguredImplementation() {
String dialect = ((SessionFactoryImpl) factory).getDialect().toString().toLowerCase();
String dialect = ((ServiceRegistryImplementor) factory).getParentServiceRegistry()
.getParentServiceRegistry().toString().toLowerCase();
if (dialect.contains("hsql")) {
return DBManager.DBImpl.HSQL;
} else if (dialect.contains("mysql")) {
@ -243,10 +247,14 @@ public abstract class AbstractDbManager<T> implements CrudManager<T> {
boolean deleted = false;
Transaction tx = null;
Session session = factory.getCurrentSession();
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(clazz);
try {
LOGGER.debug("retrieving object from db");
tx = session.beginTransaction();
Object object = session.createCriteria(clazz)
Root<T> myObjectRoot = criteria.from(clazz);
Join<T, JoinObject> joinObject = myObjectRoot.join("joinObject");
Object object = session.getSessionFactory().getCurrentSession().createCriteria(clazz)
.add(Restrictions.eq("name", name)).uniqueResult();
if (object != null && clazz.isInstance(object)) {
T objectOfTypeT = clazz.cast(object);

View File

@ -7,8 +7,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;

View File

@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
/**

View File

@ -24,7 +24,7 @@ import org.hibernate.SessionFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import hirs.alert.ManagedAlertService;
import java.util.Collection;

View File

@ -2,7 +2,7 @@ package hirs.persist.imarecord;
import hirs.FilteredRecordsList;
import hirs.data.persist.IMAMeasurementRecord;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import java.util.List;

View File

@ -13,5 +13,5 @@ persistence.db.retryWaitTimeMilliseconds = 3000
# Properties used by the Hibernate Session Factory
persistence.hibernate.dialect = hirs.utils.MySqlUtf8CompatibleDialect
persistence.hibernate.ddl = update
persistence.hibernate.contextClass = org.springframework.orm.hibernate4.SpringSessionContext
persistence.hibernate.contextClass = org.springframework.orm.hibernate5.SpringSessionContext
persistence.hibernate.provider = org.hibernate.hikaricp.internal.HikariCPConnectionProvider

View File

@ -11,5 +11,5 @@ persistence.db.retryWaitTimeMilliseconds = 1000
persistence.hibernate.dialect = org.hibernate.dialect.HSQLDialect
persistence.hibernate.ddl = create-drop
persistence.hibernate.contextClass = org.springframework.orm.hibernate4.SpringSessionContext
persistence.hibernate.contextClass = org.springframework.orm.hibernate5.SpringSessionContext
persistence.hibernate.provider = org.hibernate.hikaricp.internal.HikariCPConnectionProvider

View File

@ -96,26 +96,26 @@ subprojects {
checkstyle: 'com.puppycrawl.tools:checkstyle:10.0',
commons_cli: 'commons-cli:commons-cli:1.4',
commons_codec: 'commons-codec:commons-codec:1.15',
commons_csv: 'org.apache.commons:commons-csv:1.4',
commons_csv: 'org.apache.commons:commons-csv:1.9.0',
commons_exec: 'org.apache.commons:commons-exec:1.3',
commons_http: 'commons-httpclient:commons-httpclient:3.1',
commons_io: 'commons-io:commons-io:2.11.0',
commons_lang: 'org.apache.commons:commons-lang3:3.3.2',
commons_lang: 'org.apache.commons:commons-lang3:3.12.0',
commons_upload:'commons-fileupload:commons-fileupload:1.4',
commons_valid: 'commons-validator:commons-validator:1.7',
findbugs: 'com.google.code.findbugs:findbugs:3.0.0',
gson: 'com.google.code.gson:gson:2.9.0',
guava: 'com.google.guava:guava:31.1-jre',
hibernate: [ 'org.hibernate.common:hibernate-commons-annotations:4.0.4.Final',
'org.hibernate:hibernate-core:4.3.11.Final',
'org.hibernate:hibernate-hikaricp:4.3.11.Final'],
hikari: 'com.zaxxer:HikariCP:2.4.1',
hibernate: [ 'org.hibernate.common:hibernate-commons-annotations:5.0.0.Final',
'org.hibernate:hibernate-core:5.0.0.Final',
'org.hibernate:hibernate-hikaricp:5.0.0.Final'],
// hikari: 'com.zaxxer:HikariCP:5.0.1',
hsqldb: 'org.hsqldb:hsqldb:2.6.1',
http: 'org.apache.httpcomponents:httpclient:4.5.13',
jackson: [ 'com.fasterxml.jackson.core:jackson-core:2.13.2',
'com.fasterxml.jackson.core:jackson-databind:2.13.2.2',
'com.fasterxml.jackson.core:jackson-annotations:2.13.2'],
jadira_usertype: 'org.jadira.usertype:usertype.core:4.0.0.GA',
jadira_usertype: 'org.jadira.usertype:usertype.core:6.0.1.GA',
jcommander: 'com.beust:jcommander:1.82',
joda_time: 'joda-time:joda-time:2.10.14',
jstl: [ 'org.apache.taglibs:taglibs-standard-impl:1.2.5',
@ -137,17 +137,17 @@ subprojects {
reflections: 'org.reflections:reflections:0.10.2',
servlet_api: 'javax.servlet:javax.servlet-api:4.0.1',
slf4j: 'org.slf4j:slf4j-api:1.7.36',
spring_core: ['org.springframework:spring-aop:4.3.30.RELEASE',
'org.springframework:spring-beans:4.3.30.RELEASE',
'org.springframework:spring-context:4.3.30.RELEASE',
'org.springframework:spring-expression:4.3.30.RELEASE',
'org.springframework:spring-orm:4.3.30.RELEASE'],
spring_msg: 'org.springframework:spring-messaging:4.3.30.RELEASE',
spring_core: ['org.springframework:spring-aop:5.3.19',
'org.springframework:spring-beans:5.3.19',
'org.springframework:spring-context:5.3.19',
'org.springframework:spring-expression:5.3.19',
'org.springframework:spring-orm:5.3.19'],
spring_msg: 'org.springframework:spring-messaging:5.3.19',
spring_plugin: 'org.springframework.plugin:spring-plugin-core:2.0.0.RELEASE',
spring_retry: 'org.springframework.retry:spring-retry:1.2.2.RELEASE',
spring_test: 'org.springframework:spring-test:4.3.30.RELEASE',
spring_web: 'org.springframework:spring-web:4.3.30.RELEASE',
spring_webmvc: 'org.springframework:spring-webmvc:4.3.30.RELEASE',
spring_retry: 'org.springframework.retry:spring-retry:1.3.2',
spring_test: 'org.springframework:spring-test:5.3.19',
spring_web: 'org.springframework:spring-web:5.3.19',
spring_webmvc: 'org.springframework:spring-webmvc:5.3.19',
testng: 'org.testng:testng:7.4.0',
xml_rpc_client: 'org.apache.xmlrpc:xmlrpc-client:3.1.3',
]