Coder Social home page Coder Social logo

Comments (6)

mensinda avatar mensinda commented on July 21, 2024 2

I have also managed to reproduce it with the BytecodeEnhancerRunner.

Upstream issue https://hibernate.atlassian.net/browse/HHH-17828
Reproducer PR hibernate/hibernate-orm#7961

from quarkus.

mensinda avatar mensinda commented on July 21, 2024

Also, I tried to reproduce this with just Hibernate alone, and it looks like the error does NOT occur there. So, I would assume that this really is a Quarkus bug this time around.


My hibernate test case:

package org.hibernate.orm.test.locking;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.LockModeType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Version;
import org.hibernate.Hibernate;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@JiraKey("HHH-?????")
@Jpa(
		annotatedClasses = {
				LockFindAndLockReferencedTest.MainEntity.class,
				LockFindAndLockReferencedTest.ReferencedEntity.class
		}
)
public class LockFindAndLockReferencedTest {

	@BeforeAll
	public void setUp(EntityManagerFactoryScope scope) {
		scope.inTransaction(
				entityManager -> {
					final ReferencedEntity e1 = new ReferencedEntity( 0L );
					entityManager.persist( e1 );
					final MainEntity e3 = new MainEntity( 0L, e1 );
					entityManager.persist( e3 );
				}
		);
	}

	@Test
	public void testFindAndLockAfterLock(EntityManagerFactoryScope scope) {
		scope.inTransaction(
				entityManager -> {
                    // First find and lock the main entity
					MainEntity m = entityManager.find( MainEntity.class, 0L, LockModeType.PESSIMISTIC_WRITE );
					assertNotNull( m );
					ReferencedEntity lazyReference = m.referencedLazy();
					assertNotNull( lazyReference );
					assertFalse( Hibernate.isInitialized( lazyReference ) );

					// Then find and lock the referenced entity
                    ReferencedEntity lazyEntity = entityManager.find( ReferencedEntity.class, 0L, LockModeType.PESSIMISTIC_WRITE );
                    assertNotNull( lazyEntity );

					assertEquals( LockModeType.PESSIMISTIC_WRITE, entityManager.getLockMode( lazyEntity ) );
				} );
	}

	@Entity(name = "MainEntity2")
	public static class MainEntity {
		@Id
		private long id;

        @Version
        private long tanum;

		private String name;

		@ManyToOne(targetEntity = ReferencedEntity.class, fetch = FetchType.LAZY)
		@JoinColumn(name = "LAZY_COLUMN")
		private ReferencedEntity referencedLazy;

		protected MainEntity() {
		}

		public MainEntity(long id, ReferencedEntity lazy) {
			this.id = id;
			this.referencedLazy = lazy;
		}

		public ReferencedEntity referencedLazy() {
			return referencedLazy;
		}
	}

	@Entity(name = "ReferencedEntity2")
	public static class ReferencedEntity {

		@Id
		private long id;

        @Version
        private long tanum;

		protected ReferencedEntity() {
		}

		public ReferencedEntity(long id) {
			this.id = id;
		}
	}
}

from quarkus.

marko-bekhta avatar marko-bekhta commented on July 21, 2024

Hey @mensinda thanks for reporting this issue.

Quarkus applies a few settings that are different from the standalone Hibernate ORM configuration. Hence we've recently created this new test template to make it behave a bit closer to how Quarkus works: https://github.com/hibernate/hibernate-test-case-templates/blob/main/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java

I've tried your case using that template and the issue is reproducable within it. Could you please give it a try and report the bug to the ORM JIRA here https://hibernate.atlassian.net/browse/HHH ? Thanks!

from quarkus.

mensinda avatar mensinda commented on July 21, 2024

@marko-bekhta the existence of that specific template should probably be documented somewhere. If there is already documentation, I couldn't find any.

from quarkus.

marko-bekhta avatar marko-bekhta commented on July 21, 2024

Thanks for creating the ticket and reproducer upstream!

the existence of that specific template should probably be documented somewhere

that's a good idea, I'm not sure where to add it though ... maybe @yrodiere would have a suggestion?

from quarkus.

yrodiere avatar yrodiere commented on July 21, 2024

For Quarkus, not really, since the point of this reproducer is that it's useful only when a bug isn't actually about Quarkus.
I suppose there could be some guidance in the Quarkus issue template, but not sure we want anything specific to ORM there.

For ORM, adding stuff to the various readmes in the test case templates repo would be enough as far as I'm concerned.

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.