I'm responsible on porting existing project from Oracle to MSSQL, but keeping both functional. Legacy project uses Hibernate 3.x, but contains some number of sophisticated native queries. So I would like to know which dialect used.
Dialect is a class that acts as a bridge between Java JDBC types and SQL types, which contains the mapping between java language data type and database datatype. Dialect allows Hibernate to generate SQL optimized for a particular relational database.
Hibernate uses "dialect" configuration to know which database you are using so that it can switch to the database specific SQL generator code wherever/whenever necessary.
configure(). buildSessionFactory() : For your all of entities, Hibernate generates a native query for create tables and executes it using JDBC. In order to generate native query, Hibernate uses your entity mapping and uses the provided dialect class to map java types to database data types.
A database dialect is a configuration setting for platform independent software (JPA, Hibernate, etc) which allows such software to translate its generic SQL statements into vendor specific DDL, DML.
At last I've found the way - but it is specific for Hibernate.
//take from current EntityManager current DB Session
Session session = (Session) em.getDelegate();
//Hibernate's SessionFactoryImpl has property 'getDialect', to
//access this I'm using property accessor:
Object dialect =
org.apache.commons.beanutils.PropertyUtils.getProperty(
session.getSessionFactory(), "dialect");
//now this object can be casted to readable string:
if( dialect.toString().contains("Oracle")){
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With