Author: thomas.heute(a)jboss.com
Date: 2008-07-17 04:12:53 -0400 (Thu, 17 Jul 2008)
New Revision: 11471
Modified:
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
Log:
Rollback, it didn't try to guess the Hibernate Dialect. Don't know why so far
Modified:
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2008-07-16
21:01:37 UTC (rev 11470)
+++
branches/JBoss_Portal_Branch_2_7/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2008-07-17
08:12:53 UTC (rev 11471)
@@ -24,14 +24,20 @@
import java.lang.reflect.Method;
import java.net.URL;
+import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.util.Collection;
import java.util.Iterator;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.DialectFactory;
import org.hibernate.exception.SQLGrammarException;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@@ -213,6 +219,31 @@
/** During this step the session factory is created and the content creation is
triggered. */
protected void startService() throws Exception
{
+ // Detect the dialect if necessary
+ dialectName = config.getProperty(Environment.DIALECT);
+ if (dialectName == null)
+ {
+ String dataSourceJNDI = config.getProperty(Environment.DATASOURCE);
+ log.debug("Detecting dialect with datasource " + dataSourceJNDI +
" ...");
+ DataSource ds = (DataSource)new InitialContext().lookup(dataSourceJNDI);
+ Connection conn = null;
+ try
+ {
+ conn = ds.getConnection();
+ DatabaseMetaData meta = conn.getMetaData();
+ String databaseName = meta.getDatabaseProductName();
+ int databaseMajorVersion = getDatabaseMajorVersion(meta);
+ dialectName = DialectFactory.determineDialect(databaseName,
databaseMajorVersion).getClass().getCanonicalName();
+ config.setProperty(Environment.DIALECT, dialectName);
+ log.debug("Detected dialect " + dialectName + ", database is
(" + databaseName + "," + databaseMajorVersion + ")");
+ }
+ finally
+ {
+ IOTools.safeClose(conn);
+ }
+ }
+ log.debug("Using dialect " + dialectName);
+
//
createSessionFactory();