hibernatejpamariadb

JPA is returning my entity with ONLY the id populated, all other fields are null


JPA is returning my entity with ONLY the id populated, all other fields are null (as verified by the debugger). It is fetching the entity by doing a search on another column using a JPA Query, which results in the entity having an id of 13 (which is correct) but the rest of the fields are populated and defined in the db as not null, any ideas as to why this is happening would be great.

[I had a bunch of code listed but as it does not contribute to the answer (well more precisely the question) I removed it.]


Solution

  • Initially I was getting an error of "org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of" however the issue was that the entity was assigning nulls to all fields but the id (which are certainly not null and by constraint can not be).

    The issue was I edited the DB schema to make a timestamp field not null, but MariaDB(MySQL) had assigned '0000-00-00 00:00:00' to that column. For some reason no errors, or warning were generated, it just happily returned an entity with only the id (the primary key) set!

    I only found my mistake when I tried to persist, and it informed me that I had to persist the now required timestamp field, after updating the method used to save the entity, I reviewed the contents of the db and found the error (column containing '0000-00-00 00:00:00').