Atitit. HB Native SQL cross-database resolution principle get HB Database type run time get dialect
#-----Principle
Hibernate run-time get dialect
2010-07-28 12:59:58| Category: Software Development | reporting | font size subscription
String dialect = ((Sessionfactoryimpl) session.getsessionfactory ()). Getdialect ()
. GetClass (). GetName ();
Org.hibernate.dialect.MySQLDialect
If you are spring + hibernate, you can:
String dialect = ((Sessionfactoryimpl) gethibernatetemplate (). Getsessionfactory ()). Getdialect ()
. GetClass (). GetName ();
Author of Old Wow's Paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
#----Actual code
Private Boolean ifmysql () {
Attilax Old Wow's paw 10:24:49 May 10, 2014
String dialect = ((Sessionimpl) getsession ()). GetFactory (). Getdialect ()
. GetClass (). GetName ();
Org.hibernate.dialect.MySQLDialect
System.out.println (dialect);
if (Dialect.contains ("Mysqldialect"))
return true;
Else
return false;
}
Session session = GetSession ();
String sqlString = "SELECT * from T_mb_awardweixin where activityid="
+ Actid
+ "and openid= '"
+ UID
+ "' and DATEDIFF (D,createtime,getdate ()) =0";
To create a SQLQuery object with an SQL statement
if (Ifmysql ())
Sqlstring= "SELECT * from T_mb_awardweixin where activityid="
+ Actid
+ "and openid= '"
+ UID
+ "' and date (createtime) = Curdate ();";
List L = session.createsqlquery (sqlString)