Invalid hibernate proxy entity id
See original GitHub issueWhen trying to delete an entity, nothing happens because spring is accessing the id directly, and because it is a hibernate proxy object, the member has default 0 value, thus it thinks it is a new entity and skips altogether the delete.
From debugging, this is the relevant part of the callstack:
getField:674, ReflectionUtils (org.springframework.util)
getPropertyValue:63, DirectFieldAccessFallbackBeanWrapper (org.springframework.data.util)
getId:154, JpaMetamodelEntityInformation (org.springframework.data.jpa.repository.support)
isNew:42, AbstractEntityInformation (org.springframework.data.repository.core.support)
isNew:233, JpaMetamodelEntityInformation (org.springframework.data.jpa.repository.support)
delete:170, SimpleJpaRepository (org.springframework.data.jpa.repository.support)
At the top, in ReflectionUtils::getField(Field,Object)
method, the target
variable is of type class package.Class$HibernateProxy$HWnaDQWN
, and field is private int package.Class.id
.
Note that accessing the id
by method target.getId()
returns non-zero id, as expected.
The id
is defined inside the entity as follows:
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
Spring Boot 2.1.6.RELEASE
- Spring-core 5.1.8.RELEASE
- Hibernate-core 5.3.10.Final
- Spring-data-commons 2.1.9.RELEASE
- Spring-data-jpa 2.1.9.RELEASE
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
jpa - How to avoid initializing a Hibernate proxy when only the ...
I've tried adding @Access(AccessType.PROPERTY) like: @Entity class Continent( @Id @Access(AccessType.
Read more >How to Convert a Hibernate Proxy to a Real Entity Object
In this tutorial, we'll learn how to convert a Hibernate proxy to a real entity object.
Read more >Session (Hibernate JavaDocs) - Red Hat on GitHub
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.
Read more >How does a JPA Proxy work and how to unproxy it with ...
Learn how JPA and Hibernate Proxy objects work, and how you can unproxy an entity Proxy to get access to the underlying POJO...
Read more >hibernate-orm/LazyInitializer.java at main - proxy - GitHub
void initialize() throws HibernateException;. /**. * Retrieve the identifier value for the entity our owning proxy represents.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Opened https://jira.spring.io/browse/DATAJPA-1576
We should move that ticket to JIRA, here’s probably not the right place. I think we can improve on that end to align with JPA access rules and fetch the Id value in a better way.