Atitit. HB Native SQL cross-database resolution principle get HB Database type run time get dialect

Source: Internet
Author: User
Tags openid

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)




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.