Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session.remove && session.getReference #359

Closed
Xset-s opened this issue Sep 7, 2020 · 3 comments · Fixed by #360
Closed

session.remove && session.getReference #359

Xset-s opened this issue Sep 7, 2020 · 3 comments · Fixed by #360
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Xset-s
Copy link

Xset-s commented Sep 7, 2020

Hello, as i understand, following jpa, there is only one way to remove detached entity:

factory.withTransaction((session, transaction) -> 
	session.merge(sampleEntity).invokeUni(session::remove)
).await().indefinitely();

Everything is fine, but if it's about performance, merge operation takes large amount of time and can cause real performance troubles. For instance, according to my inaccurate time measurements, removing 5000 entities takes ~4s, in hibernate-orm it takes 50ms.

I've just read about a new method called session.getReference which returns the persistent instance of given entity. Is it possible to allow its use for session.remove?

@gavinking
Copy link
Member

I've just read about a new method called session.getReference which returns the persistent instance of given entity. Is it possible to allow its use for session.remove?

Ah, good point, absolutely you should be able to do that. I've made it work in #360.

However, I want you to understand that there's no way to remove() an object without fetching it first. That's because remove() has semantics like cascade delete, and collection removal that depend on having the state of the entity in the session.

If you absolutely need to be able to delete an entity without fetching it, you should use StatelessSession.delete() or a HQL delete query.

@gavinking gavinking added this to the FIRST CUT milestone Sep 7, 2020
@gavinking gavinking self-assigned this Sep 7, 2020
@gavinking gavinking added the bug Something isn't working label Sep 7, 2020
@DavideD DavideD closed this as completed in 9a72cd1 Sep 8, 2020
@gavinking
Copy link
Member

@Xset-s P.S. thanks for reporting this, it was a big oversight on my part

@Xset-s
Copy link
Author

Xset-s commented Sep 8, 2020

No problem, thanks for your detailed response about removing operation and for a very quick fix. I'm conducting experiments right now and rewriting my server-side application using your new amazing library, so its easy for me to catch some tricky issues, which could only be captured only so (or using a large number of tests 😄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants