HHH-17253 Test circular type variable stack overflow in metamodel generator

This commit is contained in:
Christian Beikov 2023-12-19 18:28:42 +01:00
parent b386b25676
commit fc43836c7e
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,28 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.circulartypevariable;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
import org.hibernate.jpamodelgen.test.util.TestForIssue;
import org.hibernate.jpamodelgen.test.util.TestUtil;
import org.hibernate.jpamodelgen.test.util.WithClasses;
import org.junit.Test;
import jakarta.persistence.metamodel.SetAttribute;
@TestForIssue(jiraKey = "HHH-17253")
public class CircularTypeVariableTest extends CompilationTest {
@Test
@WithClasses({ RoleAccess.class, User.class })
public void testCircularTypeVariable() {
TestUtil.assertMetamodelClassGeneratedFor( RoleAccess.class );
TestUtil.assertMetamodelClassGeneratedFor( User.class );
}
}

View File

@ -0,0 +1,28 @@
package org.hibernate.jpamodelgen.test.circulartypevariable;
import org.hibernate.annotations.Immutable;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
@MappedSuperclass
@Access( AccessType.PROPERTY )
@Immutable
public class RoleAccess<
TRoleAccess extends RoleAccess<TRoleAccess,TUser>,
TUser extends User<TUser,TRoleAccess>> {
private Long id;
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

View File

@ -0,0 +1,36 @@
package org.hibernate.jpamodelgen.test.circulartypevariable;
import java.util.Set;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.OneToMany;
@MappedSuperclass
@Access( AccessType.PROPERTY )
public class User<
TUser extends User<TUser,TRoleAccess>,
TRoleAccess extends RoleAccess<TRoleAccess,TUser>> {
private Long id;
private Set<TRoleAccess> roleAccesses;
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany
public Set<TRoleAccess> getRoleAccesses() {
return roleAccesses;
}
public void setRoleAccesses(Set<TRoleAccess> roleAccesses) {
this.roleAccesses = roleAccesses;
}
}