A quick little post on a random issue I ran into today. I don’t exactly have a good explanation for this as of yet but here’s a quick tip if you run into this problem.
So let’s define an entity for persistence (we’re using JPA and Eclipselink, to a Postgres database).
Simple. Now, what if we’re developing a front-end that queries the database, and we want to list out the fields of Foo. So let’s use reflection to list the fields, and use Java 8 stream operators.
And so that looks pretty good. Except now JPA does not generate this into the database (fails validation).
However this would work:
But that isn’t as cool as using streams. So this also works, but moving the reflection to another class; in this case the DAO.