Advertisement
| Hall of Fame |
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: |
FILENAME: "hibernate.cfg.xml"
-------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory><!-- name="java:hibernate/AupSessionFactory" (vedi sotto) -->
<!--
datasource JNDI name
-->
<property name="hibernate.connection.datasource">java:jdbc/aup_db</property>
<!--
The classname of a TransactionFactory to use with Hibernate Transaction API (defaults to JDBCTransactionFactory).
eg. classname.of.TransactionFactory
-->
<!--property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property--><!-- JTATransactionFactory || ... -->
<!--
A JNDI name used by JTATransactionFactory to obtain the JTA UserTransaction from the application server.
eg. jndi/composite/name
-->
<!--property name="jta.UserTransaction">java:comp/UserTransaction</property--><!-- java:comp/UserTransaction IS THE DEFAULT ONE -->
<!--
The classname of a TransactionManagerLookup - required when JVM-level caching is enabled or when using hilo generator in a JTA environment.
eg. classname.of.TransactionManagerLookup
-->
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property><!-- JBossTransactionManagerLookup || JDBCTransactionFactory || JNDITransactionManagerLookup || ... -->
<!--
The classname of a Hibernate Dialect which allows Hibernate to generate SQL optimized for a particular relational database.
eg. full.classname.of.Dialect
-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property><!-- HSQLDialect MySQLDialect MySQLInnoDBDialect MySQLMyISAMDialect PostgreSQLDialect -->
<!--
Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.
eg. true | false
-->
<property name="hibernate.show_sql">false</property><!-- false -->
<!--
Pretty print the SQL in the log and console.
eg. true | false
-->
<property name="hibernate.format_sql">true</property><!-- false -->
<!--
The SessionFactory will be automatically bound to this name in JNDI after it has been created.
eg. jndi/composite/name
-->
<property name="hibernate.session_factory_name">java:hibernate/AupSessionFactory</property>
<!--
If enabled, Hibernate will collect statistics useful for performance tuning.
eg. true | false
PS:
If you enable hibernate.generate_statistics, Hibernate will expose a number of metrics that are useful when
tuning a running system via SessionFactory.getStatistics().
Hibernate can even be configured to expose these statistics via JMX.
Read the Javadoc of the interfaces in org.hibernate.stats for more information.
-->
<property name="hibernate.generate_statistics">true</property>
<!--
If turned on, Hibernate will generate comments inside the SQL, for easier debugging, defaults to false.
eg. true | false
-->
<property name="hibernate.use_sql_comments">true</property><!-- Set this to true ONLY for debug purposes --><!-- false -->
<!--
Specify when Hibernate should release JDBC connections.
By default, a JDBC connection is held until the session is explicitly closed or disconnected.
For an application server JTA datasource, you should use after_statement to aggressively release connections after every JDBC call.
For a non-JTA connection, it often makes sense to release the connection at the end of each transaction, by using after_transaction.
auto will choose after_statement for the JTA and CMT transaction strategies and after_transaction for the JDBC transaction strategy.
eg. auto (default) | on_close | after_transaction | after_statement
Note that this setting only affects Sessions returned from SessionFactory.openSession.
For Sessions obtained through SessionFactory.getCurrentSession, the CurrentSessionContext implementation configured for use controls the
connection release mode for those Sessions. See Section 2.5, âÃÂÃÂContextual SessionsâÃÂÃÂ
-->
<property name="hibernate.connection.release_mode">auto</property><!-- For an application server JTA datasource, use after_statement -->
<!--
Supply a (custom) strategy for the scoping of the "current" Session.
See Section 2.5, âÃÂÃÂContextual SessionsâÃÂàfor more information about the built-in strategies.
eg. jta | thread | managed | custom.Class
-->
<property name="hibernate.current_session_context_class">thread</property><!-- use jta for connections managed by JBoss || use thread for JDBC: this setting can change your HibernateUtil and application implementation -->
<!--
Enables autocommit for JDBC pooled connections (not recommended).
eg. true | false
-->
<property name="hibernate.connection.autocommit">false</property>
<!-- #################################### Inizio modifica specifica per MySQL #################################### -->
<!--
hibernate.connection.<propertyName>
Pass the JDBC property propertyName to DriverManager.getConnection().
-->
<property name="hibernate.connection.zeroDateTimeBehaviour">convertToNull</property>
<!-- #################################### Fine modifica specifica per MySQL #################################### -->
<!-- #################################### Inizio modifica specifica per ??? #################################### -->
<!--
hibernate.jndi.<propertyName>
Pass the property propertyName to the JNDI InitialContextFactory.
-->
<!--
<property name="hibernate.jndi.class">org.jnp.interfaces.NamingContextFactory</property>
-->
<!-- #################################### Fine modifica specifica per ??? #################################### -->
<!--
mapping files
-->
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Device.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/DeviceCatalog.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/DeviceParam.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Email.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Home.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/InstantMessenger.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Location.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Logservice.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Mobile.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/PlacetypeCatalog.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/ServiceCatalog.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User2home.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User2vehicle.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/User2work.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/UsrServiceProf.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/UsrServiceProfParam.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Vehicle.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/VirtualPlace.hbm.xml" />
<mapping resource="com/tilab/ca/platform/aup/dto/hibernate/Work.hbm.xml" />
</session-factory>
</hibernate-configuration>
-------------------------------------------------------
FILENAME: "PlainJDBCHibernateUtil.java"
-------------------------------------------------------
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class PlainJDBCHibernateUtil {
/**
* Location of "hibernate.cfg.xml" file.
* Location should be on the classpath as Hibernate uses #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is in the default package.
* Use #setConfigFile() to update the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "hibernate.cfg.xml";//"hibernate.cfg.xml" || "another_hibernate.cfg.xml"
private static final ThreadLocal threadLocal = new ThreadLocal();
private static Configuration configuration = new Configuration();
private static SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
sessionFactory = configuration.configure(configFile).buildSessionFactory();
} catch (Exception e) {
//Make sure you log the exception, as it might be swallowed
System.err.println("%%%% Error Creating SessionFactory %%%%");
throw new ExceptionInInitializerError(e);
}
}
/**
*
*/
private PlainJDBCHibernateUtil() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize the <code>SessionFactory</code> if needed.
* @return Session
* @throws HibernateException
*/
public static Session getCurrentSession() throws HibernateException {//getCurrentSession() instead of getSession()
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
//If you use "sessionFactory.openSession()" you MUST handle your Session i.e. session.flush(), session.close(), ...
//A BETTER WAY of handling your Session is to use "sessionFactory.getCurrentSession()".
session = (sessionFactory != null) ? sessionFactory.getCurrentSession() : null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*/
public static void rebuildSessionFactory() {
try {
sessionFactory = configuration.configure(configFile).buildSessionFactory();
} catch (Exception e) {
//Make sure you log the exception, as it might be swallowed
System.err.println("%%%% Error Creating SessionFactory %%%%");
throw new ExceptionInInitializerError(e);
}
}
/**
* Close the single hibernate session instance.
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
* @return SessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* set hibernate configuration<br/>
* Session factory is set to null and will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
PlainJDBCHibernateUtil.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
* @return Configuration
*/
public static Configuration getConfiguration() {
return configuration;
}
}
-------------------------------------------------------
|