[jboss-jira] [JBoss JIRA] (WFLY-11793) JPA EntityManager merge infinite loop - java.lang.StackOverflowError
James Perkins (Jira)
issues at jboss.org
Fri May 31 12:36:00 EDT 2019
[ https://issues.jboss.org/browse/WFLY-11793?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James Perkins updated WFLY-11793:
---------------------------------
Steps to Reproduce:
Perform the following mapping with JPA:
{code:java}
public class Papel{
....
@OneToMany(mappedBy = "id.papel", cascade = { CascadeType.ALL }, orphanRemoval = true)
private List<PermissaoAtribuida> permissoesAtribuidas = new ArrayList<>();
....
}
{code}
{code:java}
public class Permissao{
....
@Id
@Getter
@Setter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PK", insertable = false, updatable = false)
private Integer id;
....
}
{code}
{code:java}
public class PermissaoAtribuida{
....
@EmbeddedId
private Id id;
@Embeddable
@EqualsAndHashCode(of = { "permissao", "papel" })
public static class Id{
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_PERMISSAO", nullable = false)
private Permissao permissao;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_PAPEL", nullable = false)
private Papel papel;
}
....
}
{code}
And invoke the following code snippet, whereas papelServico is an EJB abstracting the DAO layer:
{code:java}
Papel papel = new Papel();
papel.setNome("Insert");
papelServico.insert(papel);
Permissao permissao = ...
List<PermissaoAtribuida> l = new ArrayList<>();
l.add(new PermissaoAtribuida(permissao, papel));
papel.setPermissoesAtribuidas(l);
papel.setNome("Update");
papelServico.update(papel);
{code}
This problem only occurs if the permissaoAtribuida properties of class Papel are mapped with cascade = {CascadeType.ALL}.
was:
Perform the following mapping with JPA:
public class Papel{
....
@OneToMany(mappedBy = "id.papel", cascade = { CascadeType.ALL }, orphanRemoval = true)
private List<PermissaoAtribuida> permissoesAtribuidas = new ArrayList<>();
....
}
public class Permissao{
....
@Id
@Getter
@Setter
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PK", insertable = false, updatable = false)
private Integer id;
....
}
public class PermissaoAtribuida{
....
@EmbeddedId
private Id id;
@Embeddable
@EqualsAndHashCode(of = { "permissao", "papel" })
public static class Id{
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_PERMISSAO", nullable = false)
private Permissao permissao;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_PAPEL", nullable = false)
private Papel papel;
}
....
}
And invoke the following code snippet, whereas papelServico is an EJB abstracting the DAO layer:
Papel papel = new Papel();
papel.setNome("Insert");
papelServico.insert(papel);
Permissao permissao = ...
List<PermissaoAtribuida> l = new ArrayList<>();
l.add(new PermissaoAtribuida(permissao, papel));
papel.setPermissoesAtribuidas(l);
papel.setNome("Update");
papelServico.update(papel);
This problem only occurs if the permissaoAtribuida properties of class Papel are mapped with cascade = {CascadeType.ALL}.
> JPA EntityManager merge infinite loop - java.lang.StackOverflowError
> --------------------------------------------------------------------
>
> Key: WFLY-11793
> URL: https://issues.jboss.org/browse/WFLY-11793
> Project: WildFly
> Issue Type: Bug
> Components: JPA / Hibernate
> Affects Versions: 15.0.1.Final
> Environment: MAC OS Mojave
> Java 11
> Wildfly 15.0.1-Final
> Data Base Postgresql
> Reporter: Bruno Maioli Martins
> Assignee: Scott Marlow
> Priority: Critical
> Attachments: jstack.txt, server+querys.log, server-1.log, teste.zip
>
>
> Dear,
> When executing the update of a record invoking getEntityManager().merge(obj) the application goes into infinite loop. This behavior only occurs when there is a OneToMany bidirectional mapping of the entity Papel -> PermissaoAtribuida.
> If the same code runs outside of the Wildfly server context its execution occurs normally.
> Apparently the call getEntityManager.().merge(obj) attempts infinite selects to sync the object with transaction context before doing the merge.
> Attach the source code of my test classes.
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
More information about the jboss-jira
mailing list