Skip to content

Commit

Permalink
Hibernate 6: Fixed caching of user XmlGregorianCalendar user type
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed May 15, 2023
1 parent 1cdf9df commit 43e79b8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import com.evolveum.midpoint.util.exception.SystemException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.hibernate.Criteria;
//import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.hql.spi.QueryTranslatorFactory;
import org.hibernate.internal.CriteriaImpl;
//import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
//import org.hibernate.hql.spi.QueryTranslator;
//import org.hibernate.hql.spi.QueryTranslatorFactory;
//import org.hibernate.internal.CriteriaImpl;
import org.hibernate.internal.SessionImpl;
import org.hibernate.loader.OuterJoinLoader;
import org.hibernate.loader.criteria.CriteriaLoader;
//import org.hibernate.loader.OuterJoinLoader;
//import org.hibernate.loader.criteria.CriteriaLoader;
import org.hibernate.persister.entity.OuterJoinLoadable;

import java.lang.reflect.Field;
Expand All @@ -37,6 +37,7 @@ public class HibernateToSqlTranslator {
* @param criteria
* @return SQL string, null if criteria parameter was null.
*/
/*
public static String toSql(Criteria criteria) {
if (criteria == null) {
return null;
Expand All @@ -62,6 +63,7 @@ public static String toSql(Criteria criteria) {
throw new SystemException(ex.getMessage(), ex);
}
}
*/

/**
* Do not use in production code! Only for testing purposes only. Used for example during query engine upgrade.
Expand All @@ -71,6 +73,7 @@ public static String toSql(Criteria criteria) {
* @param hqlQueryText
* @return SQL string, null if hqlQueryText parameter is empty.
*/
/*
public static String toSql(SessionFactory sessionFactory, String hqlQueryText) {
Validate.notNull(sessionFactory, "Session factory must not be null.");
Expand All @@ -90,4 +93,5 @@ public static String toSql(SessionFactory sessionFactory, String hqlQueryText) {
translator.compile(Collections.EMPTY_MAP, false);
return translator.getSQLString();
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ protected void close(Session session) {
}

String hqlToSql(String hql) {
return HibernateToSqlTranslator.toSql(factory, hql);
//return HibernateToSqlTranslator.toSql(factory, hql);
throw new UnsupportedOperationException("Not migrated to Hibernate 6");
}

protected <O extends ObjectType> PrismObject<O> getObject(Class<O> type, String oid) throws ObjectNotFoundException, SchemaException {
Expand Down Expand Up @@ -310,6 +311,7 @@ protected void displayValue(String title, DebugDumpable value) {
displayDumpable(title, value);
}

@Override
public void displayValue(String title, Object value) {
PrismTestUtil.display(title, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.query.Query;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -228,6 +225,7 @@ public void test001addOrgStructObjectsIncorrect() throws Exception {
Session session = open();
try {
logger.info("==============CLOSURE TABLE==========");
/*
// descendants of F007 - F007<0>, F009<1>, F008<2>, F0010<2>
Criteria criteria = session.createCriteria(ROrgClosure.class)
.createCriteria("ancestor", "anc")
Expand All @@ -247,7 +245,7 @@ public void test001addOrgStructObjectsIncorrect() throws Exception {
orgClosure = criteria.list();
AssertJUnit.assertEquals(3, orgClosure.size());

*/
ObjectQuery query = prismContext.queryFor(UserType.class)
.item(UserType.F_NAME).eq(ELAINE_NAME1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import org.assertj.core.api.Assertions;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;
import org.hibernate.type.StandardBasicTypes;
import org.jgrapht.alg.TransitiveClosure;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.SimpleDirectedGraph;
Expand Down Expand Up @@ -175,9 +174,9 @@ protected boolean checkClosureMatrix() throws SchemaException {
if (DUMP_TC_MATRIX_DETAILS) { logger.info("TC matrix expected = {}", result); }

Query q = session.createNativeQuery("select descendant_oid, ancestor_oid, val from m_org_closure")
.addScalar("descendant_oid", StringType.INSTANCE)
.addScalar("ancestor_oid", StringType.INSTANCE)
.addScalar("val", LongType.INSTANCE);
.addScalar("descendant_oid", StandardBasicTypes.STRING)
.addScalar("ancestor_oid", StandardBasicTypes.STRING)
.addScalar("val", StandardBasicTypes.LONG);
List<Object[]> list = q.list();
logger.info("OrgClosure has {} rows", list.size());

Expand Down
2 changes: 1 addition & 1 deletion repo/repo-sql-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakaerta.persistence-api</artifactId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>

<!-- H2 -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sql.query.restriction;

public enum MatchMode {
ANYWHERE, START, END

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public XMLGregorianCalendar assemble(Serializable cached, Object owner) throws H
if (cached == null) {
return null;
}
if (cached instanceof XMLGregorianCalendar) {
return (XMLGregorianCalendar) ((XMLGregorianCalendar) cached).clone();
}
long date = (Long) cached;

return asXMLGregorianCalendar(new Date(date));
Expand All @@ -62,6 +65,7 @@ public int getSqlType() {
return JPA_TYPE.getSqlTypeCode();
}


@Override
public Class<XMLGregorianCalendar> returnedClass() {
return XMLGregorianCalendar.class;
Expand Down Expand Up @@ -123,9 +127,9 @@ public Serializable disassemble(XMLGregorianCalendar value) throws HibernateExce
if (value == null) {
return null;
}

XMLGregorianCalendar calendar = value;
return asDate(calendar).getTime();
return (Serializable) value.clone();
//XMLGregorianCalendar calendar = value;
//return asDate(calendar).getTime();
}

@Override
Expand Down

0 comments on commit 43e79b8

Please sign in to comment.