JPA / Hibernate PropertyNotFoundException – Troubleshooting and fixes




In this post, we discuss yet another reason for having a mapping error from Hibernate. This specific one is called a PropertyNotFoundException. If you have made sure that your property is correctly mapped to the database table, with correct column names and a getter and a setter for the property, then read on!.  Let us get started by checking our faulty code:







If we attempt to start up our application, we will get the following error message:




Notice the most inner cause is a PropertyNotFoundException.


Did you notice the bug?


Taking a look at the code, we can see that the property does exist. A getter and a setter do exist for the zipCode property as well. So what was the issue?


The issue is that Hibernate expects that you follow a standard JavaBean pattern, implementing getters and setters for each property. Hibernate also expects that your setter takes as an argument the value of the property to be set. Since our setter had no arguments, Hibernate could not find a setter to work with. To correct this issue, we simply add another setter to our class which takes the zipCode as an argument. If you do not want to expose that setter, you can simply set the setter access to “private”. Hibernate uses reflection to find the getters and setters, so the protection level should not matter.




If you have liked this content, then please follow us on twitter by clicking on the follow button below in order to get our latest updates 🙂