title: Elegant ways to handle database views on hibernate entities?
body: <p>One of the main reasons I use Hibernate is that it provides the flexibility to switch to another database without having to rewrite any code. </p>
  
  <p>But until now I did not figure out a good way to define additional views on the tables to which my hibernate entities are matched; I am still using simple SQL scripts for that. Is there a more elegant way to define views on tables managed by hibernate? </p>
  
  <p>Ideally I would like to use HQL or another generic method to do the job, so that I don't have to worry about my SQL scripts being incompatible with other kinds of databases.</p>
  
  <p>If there's a way to do that, a second issue would then be to get 'synthetic' read-only instances from these views, which should make it much easier to feed the aggregated data into a UI.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It seems as if I didn't make the problem clear enough, so here's what i am trying to do: I want to write code that is independent of the used database. Since I use hibernate, I would just have to change the dialect configuration file and could then use another DBMS. </p>
  
  <p>Question: how to create <em>views</em> on my hibernate entities <em>without</em> relying on a specific SQL dialect (to keep everything portable), or even HQL? And if that's possible, can I use HQL to also query these views, i.e. to create read-only aggregate entities? Is there any additional hibernate plug-in to help me with that? Haven't found anything so far... :-/</p>