I have a JPA entity that I use as the result class of a native query. As such, the entity is not valid per se (as it does not have a table). I use Hibernate 4.1.x as my JPA provider, which performs a schema validation during startup and consequently fails (I did not specify an explicit table):
org.hibernate.HibernateException: Missing table: MyEntity
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1272)
[...]
Is there a way to turn off schema validation for just a single entity (using JPA or hibernate annotations or a change of persistence.xml)?
Edit: I can completely avoid using any entity as a result, but then Hibernate will return a List<Object[]>
as query result, which technically works, but is a little ugly to use:
Query query = entityManager.get().createNativeQuery("SELECT node, last_update FROM mm_repl_monitoring.my_mm_nodes");
List<Object[]> statuses = query.getResultList();
In other words: It would be nice if there was some mapping support that can be used even for native queries that map to non-Entity classes.