Reputation: 179
I'm trying to create a new Play application using JPA / Hibernate from an existing Mysql database.
hibernate.hbm2ddl.auto
in persistence file is set to "update".
My table posts has 6 entries.
Problem is when I execute an HQL statement like "SELECT p FROM Posts p"
, I got an empty result, while if I execute a native query like "SELECT * FROM posts"
I got my existing entries.
I think I'm missing something huge here, like hibernate's internal caching system or something, is there anything like this that can explain this empty result ? Does Hibernate has to build some specific cache when used from an existing database so that it returns correct results with HQL statements ? Why would it need such a thing ?
Upvotes: 0
Views: 1268
Reputation: 1235
My table posts has 6 entries. Problem is when I execute an HQL statement like "SELECT p FROM Posts p", I got an empty result, while if I execute a native query like "SELECT * FROM posts" I got my existing entries.
This sounds like you have to define mappings from mysql tables to jpa entities. You can generate them automatically using hibernate tools (like see an example here on how to do that using an Eclipse plugin).
You should get some results from your query after that, Hibernate will populate its caches along the way.
Upvotes: 1