[hibernate-issues] [JIRA] (HHH-13942) >= 5.4.4.Final Causes Version issue with QueryDSL

Joy Reistad (JIRA) jira at hibernate.atlassian.net
Wed Apr 8 13:49:26 EDT 2020


Joy Reistad ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Aa0625ae6-266a-49f2-86e2-38b4407fdbd4 ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjkyYzBhMzYxYTUyNGQ0Y2FlYTg0YzM0OWVmMjk3YjYiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13942?atlOrigin=eyJpIjoiNjkyYzBhMzYxYTUyNGQ0Y2FlYTg0YzM0OWVmMjk3YjYiLCJwIjoiaiJ9 ) HHH-13942 ( https://hibernate.atlassian.net/browse/HHH-13942?atlOrigin=eyJpIjoiNjkyYzBhMzYxYTUyNGQ0Y2FlYTg0YzM0OWVmMjk3YjYiLCJwIjoiaiJ9 ) >= 5.4.4.Final Causes Version issue with QueryDSL ( https://hibernate.atlassian.net/browse/HHH-13942?atlOrigin=eyJpIjoiNjkyYzBhMzYxYTUyNGQ0Y2FlYTg0YzM0OWVmMjk3YjYiLCJwIjoiaiJ9 )

Issue Type: Bug Affects Versions: 5.4.4 Assignee: Unassigned Created: 08/Apr/2020 10:49 AM Priority: Major Reporter: Joy Reistad ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Aa0625ae6-266a-49f2-86e2-38b4407fdbd4 )

My team uses hibernate-core and hibernate-c3p0.
we recently tried to upgrade from version 5.4.1.Final to latest (5.4.14.Final) however this caused our version field to stop updating.
Dug in and found this change starts happening on version 5.4.4.Final.

Hibernate usage:
We use hibernate with queryDSL and javax.persistence
We use javax.Persistence to create an entityManagerFactory with a set of hibernate properties

ImmutableMap.Builder< String , String > properties = ImmutableMap.< String , String >builder()
		.put( "hibernate.connection.url" , dbConnectionString)
		.put( "hibernate.connection.user" , dbUser)
		.put( "hibernate.connection.password" , dbPassword)
		.put( "hibernate.c3p0.min_size" , minDbConnections)
		.put( "hibernate.c3p0.max_size" , maxDbConnections)
		.put( "hibernate.c3p0.timeout" , connectionTimeout)
		.put( "hibernate.c3p0.preferredTestQuery" , " /* ping */ SELECT 1" )
		.put( "hibernate.connection.Charset" , "utf8" )
		.put( "hibernate.connection.characterEncoding" , "utf8" )
		.put( "hibernate.connection.useUnicode" , " true " );

if (connectionTestOnCheckout) {
	properties.put( "hibernate.c3p0.testConnectionOnCheckout" , " true " );
} else {
	if (connectionTestOnCheckin) {
		properties.put( "hibernate.c3p0.testConnectionOnCheckin" , " true " );
	}
	properties.put( "hibernate.c3p0.idle_test_period" , dbIdleCheckInterval);
}

entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, properties.build());

We use the javax.persistence @Entity annotations to represent our object being stored int the db. And we have a version attribute with the @Version annotation

import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name = "obj" , schema = "schema" )
public class MyObject {

	public MyObject() {
	}

	@Id
	@Column(name = "id" )
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Version
	@Column(name = "version" )
	private Long version;

	public Long getId() {
		return id;
	}

	public MyObject setId( Long id) {
		this.id = id;
		return this ;
	}

	public Long getVersion() {
		return version;
	}

	public MyObject setVersion( Long version) {
		this.version = version;
		return this ;
	}
}

*We use the LockModeType.WRITE on some of our JPAQueries to force an update to the version object when needed.
however since the hibernate update, entityManager.clear() is clearing the version updates, so the version is not updated ever*

MyObj myObj = new MyObj().setVersion(1L);
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
em.persist(myObj);
em.getTransaction().commit();
em.close();
MyTransaction transaction = new MyTransaction(entityManagerFactory.createEntityManager());
transaction.incrementVersion(myObj.getId);
transaction.commit();

mport javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.RollbackException;

import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;

public class MyTransaction{

	private final EntityManager entityManager;
	private final JPAQueryFactory queryFactory;

	public MyTransaction(EntityManager entityManager) {
		this.entityManager = entityManager
		this.queryFactory = new JPAQueryFactory(entityManager);
		entityManager.setFlushMode(FlushModeType.COMMIT);
		entityManager.getTransaction().begin();
	}

	public void commit() {
		//Detaches all JPA managed entities, so that only our explicit updates are persisted. version should still be automatically updated via QueryDSL.
		entityManager.clear(); 
		try {
			entityManager.getTransaction().commit();
		} catch (RollbackException e) {
			throw e;
		}
	}

	public void incrementVersion( Long id) {
		//QMyObj is a Querydsl query type for MyObj
		JPAQuery<MyObj> query = queryFactory.selectFrom(QMyObj.myObj)
				.where(QMyObj.myObj.id.eq(id));
		query.setLockMode(LockModeType.WRITE);
		query.fetchOne();
	}

	public void close() {
		try {
			if (entityManager.isJoinedToTransaction()) {
				entityManager.getTransaction().rollback();
			}
		} finally {
			entityManager.close();
		}
	}

( https://hibernate.atlassian.net/browse/HHH-13942#add-comment?atlOrigin=eyJpIjoiNjkyYzBhMzYxYTUyNGQ0Y2FlYTg0YzM0OWVmMjk3YjYiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13942#add-comment?atlOrigin=eyJpIjoiNjkyYzBhMzYxYTUyNGQ0Y2FlYTg0YzM0OWVmMjk3YjYiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100124- sha1:c13ca0d )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200408/743c1c0a/attachment.html 


More information about the hibernate-issues mailing list