title: How to get Hibernate dialect during runtime
body: <p><br />
  In my application, I use Hibernate with SQL Server database, so I set</p>
  
  <pre><code>&lt;property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"&gt;
  </code></pre>
  
  <p>in my persistence.xml.</p>
  
  <p>In some case, I want to sort records with NULL include, I use keyword NULLS FIRST.<br />
  Because it is not supported by default by CriteriaQuery/CriteriaBuilder in Hibernate, then I use Interceptor to modify the native query.<br />
  The problem is, keyword NULLS FIRST is not supported in SQL Server, so I use keyword:</p>
  
  <pre><code>case when column_name is null then 0 else 1 end, column_name
  </code></pre>
  
  <p>If I want to migrate database from SQL Server to Oracle (for example), then I need to put if-else in my Interceptor, choosing which dialect I am using, right?<br /></p>
  
  <p>This is how I illustrate them:</p>
  
  <pre><code>String dialect = ..............
  if (dialect.equals("org.hibernate.dialect.SQLServerDialect")) { // get SQL Server dialect
       // put keyword "case when column_name is null then 0 else 1 end, column_name"
  } else {
       // put keyword "NULLS FIRST/LAST"
  }
  </code></pre>
  
  <p>How I can get the dialect configuration (in persistence.xml) during runtime?</p>