lazyinitalizationexception with wildfly 14: could not initialize proxy - the owning session was closed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
If I run my code with wildfly 14 server I get following excpetion. The same code worked with wildfly 13. Where could be the problem?
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [ch.example.tool.entity.Benutzer#12] - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:172)
at org.hibernate.proxy.AbstractLazyInitializer.getIdentifier(AbstractLazyInitializer.java:89)
at org.hibernate.internal.SessionImpl.getProxyIdentifier(SessionImpl.java:1752)
at org.hibernate.internal.SessionImpl.getContextEntityIdentifier(SessionImpl.java:1743)
at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:271)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:495)
at org.hibernate.type.EntityType.nullSafeSet(EntityType.java:280)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2868)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3307)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3229)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3630)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:146)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)
... 122 more
spring hibernate wildfly jta transactional
add a comment |
If I run my code with wildfly 14 server I get following excpetion. The same code worked with wildfly 13. Where could be the problem?
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [ch.example.tool.entity.Benutzer#12] - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:172)
at org.hibernate.proxy.AbstractLazyInitializer.getIdentifier(AbstractLazyInitializer.java:89)
at org.hibernate.internal.SessionImpl.getProxyIdentifier(SessionImpl.java:1752)
at org.hibernate.internal.SessionImpl.getContextEntityIdentifier(SessionImpl.java:1743)
at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:271)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:495)
at org.hibernate.type.EntityType.nullSafeSet(EntityType.java:280)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2868)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3307)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3229)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3630)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:146)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)
... 122 more
spring hibernate wildfly jta transactional
add a comment |
If I run my code with wildfly 14 server I get following excpetion. The same code worked with wildfly 13. Where could be the problem?
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [ch.example.tool.entity.Benutzer#12] - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:172)
at org.hibernate.proxy.AbstractLazyInitializer.getIdentifier(AbstractLazyInitializer.java:89)
at org.hibernate.internal.SessionImpl.getProxyIdentifier(SessionImpl.java:1752)
at org.hibernate.internal.SessionImpl.getContextEntityIdentifier(SessionImpl.java:1743)
at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:271)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:495)
at org.hibernate.type.EntityType.nullSafeSet(EntityType.java:280)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2868)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3307)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3229)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3630)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:146)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)
... 122 more
spring hibernate wildfly jta transactional
If I run my code with wildfly 14 server I get following excpetion. The same code worked with wildfly 13. Where could be the problem?
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [ch.example.tool.entity.Benutzer#12] - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:172)
at org.hibernate.proxy.AbstractLazyInitializer.getIdentifier(AbstractLazyInitializer.java:89)
at org.hibernate.internal.SessionImpl.getProxyIdentifier(SessionImpl.java:1752)
at org.hibernate.internal.SessionImpl.getContextEntityIdentifier(SessionImpl.java:1743)
at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:271)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:495)
at org.hibernate.type.EntityType.nullSafeSet(EntityType.java:280)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2868)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3307)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3229)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3630)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:146)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)
... 122 more
spring hibernate wildfly jta transactional
spring hibernate wildfly jta transactional
asked Nov 16 '18 at 17:29
surfspidersurfspider
1621212
1621212
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I have to explicitly load the lazy proxy reference for the merge operation in Wildfly 14. Like this it works.
Wildfly 13 and before:
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
em.merge(vergleich);
}
}
Wildfly 14
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
Benutzer benutzer = em.find(Benutzer.class, vergleich.getBenutzer().getId());
vergleich.setBenutzer(benutzer);
em.merge(vergleich);
}
}
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
add a comment |
I also opted for a workaround, all entities @ManyToOne have been annotated with @NotAudited, so Envers does not try to load them after entityManager is closed. Works for now, seems to be a Hibernate bug.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342712%2flazyinitalizationexception-with-wildfly-14-could-not-initialize-proxy-the-own%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have to explicitly load the lazy proxy reference for the merge operation in Wildfly 14. Like this it works.
Wildfly 13 and before:
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
em.merge(vergleich);
}
}
Wildfly 14
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
Benutzer benutzer = em.find(Benutzer.class, vergleich.getBenutzer().getId());
vergleich.setBenutzer(benutzer);
em.merge(vergleich);
}
}
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
add a comment |
I have to explicitly load the lazy proxy reference for the merge operation in Wildfly 14. Like this it works.
Wildfly 13 and before:
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
em.merge(vergleich);
}
}
Wildfly 14
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
Benutzer benutzer = em.find(Benutzer.class, vergleich.getBenutzer().getId());
vergleich.setBenutzer(benutzer);
em.merge(vergleich);
}
}
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
add a comment |
I have to explicitly load the lazy proxy reference for the merge operation in Wildfly 14. Like this it works.
Wildfly 13 and before:
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
em.merge(vergleich);
}
}
Wildfly 14
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
Benutzer benutzer = em.find(Benutzer.class, vergleich.getBenutzer().getId());
vergleich.setBenutzer(benutzer);
em.merge(vergleich);
}
}
I have to explicitly load the lazy proxy reference for the merge operation in Wildfly 14. Like this it works.
Wildfly 13 and before:
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
em.merge(vergleich);
}
}
Wildfly 14
@Transactional
public class VergleichDAOImpl implements VergleichDAO {
@PersistenceContext
private EntityManager em;
@Override
public void save(Vergleich vergleich) {
if(vergleich.getId() == null) {
em.persist(vergleich);
} else {
Benutzer benutzer = em.find(Benutzer.class, vergleich.getBenutzer().getId());
vergleich.setBenutzer(benutzer);
em.merge(vergleich);
}
}
answered Nov 20 '18 at 13:28
surfspidersurfspider
1621212
1621212
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
add a comment |
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
What is closing the session, in my similar problem it is Spring, are you using Spring. The solution you are proposing is a workaround, I think the actual root of the cause needs to be resolved. I have written to Hibernate, but they suggest it is a Spring problem. Maybe it is a Wildfly problem. Did you resolve this, I have the exact same problem. The workaround that you gave is not plauseble for a fullblown enterprise project. I'm using Wildfly 15, upgrade from Wildfly 10, is it a bug in Wildfly?
– Tim Mickelson
Dec 27 '18 at 9:49
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
You are right my solution is only a workaround. Sorry I didn't investigate more time to find out the origin of the problem. Perhaps there is bugfix in WF15?
– surfspider
Dec 28 '18 at 15:31
add a comment |
I also opted for a workaround, all entities @ManyToOne have been annotated with @NotAudited, so Envers does not try to load them after entityManager is closed. Works for now, seems to be a Hibernate bug.
add a comment |
I also opted for a workaround, all entities @ManyToOne have been annotated with @NotAudited, so Envers does not try to load them after entityManager is closed. Works for now, seems to be a Hibernate bug.
add a comment |
I also opted for a workaround, all entities @ManyToOne have been annotated with @NotAudited, so Envers does not try to load them after entityManager is closed. Works for now, seems to be a Hibernate bug.
I also opted for a workaround, all entities @ManyToOne have been annotated with @NotAudited, so Envers does not try to load them after entityManager is closed. Works for now, seems to be a Hibernate bug.
answered Jan 2 at 10:34
Tim MickelsonTim Mickelson
1247
1247
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342712%2flazyinitalizationexception-with-wildfly-14-could-not-initialize-proxy-the-own%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown