Package org.hibernate.cfg
Class Environment
java.lang.Object
org.hibernate.cfg.Environment
Provides access to configuration info passed in Properties objects.
Hibernate has two property scopes:
The SessionFactory is controlled by the following properties. Properties may be either be System properties, properties defined in a resource named /hibernate.properties or an instance of java.util.Properties passed to Configuration.buildSessionFactory()
Hibernate has two property scopes:
- Factory-level properties may be passed to the SessionFactory when it instantiated. Each instance might have different property values. If no properties are specified, the factory calls Environment.getProperties().
- System-level properties are shared by all factory instances and are always determined by the Environment properties.
- hibernate.jdbc.use_streams_for_binary
- hibernate.cglib.use_reflection_optimizer
The SessionFactory is controlled by the following properties. Properties may be either be System properties, properties defined in a resource named /hibernate.properties or an instance of java.util.Properties passed to Configuration.buildSessionFactory()
| property | meaning |
| hibernate.dialect | classname of org.hibernate.dialect.Dialect subclass |
| hibernate.cache.provider_class | classname of org.hibernate.cache.CacheProvider subclass (if not specified EHCache is used) |
| hibernate.connection.provider_class | classname of org.hibernate.connection.ConnectionProvider subclass (if not specified hueristics are used) |
| hibernate.connection.username | database username |
| hibernate.connection.password | database password |
| hibernate.connection.url | JDBC URL (when using java.sql.DriverManager) |
| hibernate.connection.driver_class | classname of JDBC driver |
| hibernate.connection.isolation | JDBC transaction isolation level (only when using java.sql.DriverManager) | hibernate.connection.pool_size | the maximum size of the connection pool (only when using java.sql.DriverManager) |
| hibernate.connection.datasource | databasource JNDI name (when using javax.sql.Datasource) |
| hibernate.jndi.url | JNDI InitialContext URL |
| hibernate.jndi.class | JNDI InitialContext classname |
| hibernate.max_fetch_depth | maximum depth of outer join fetching |
| hibernate.jdbc.batch_size | enable use of JDBC2 batch API for drivers which support it |
| hibernate.jdbc.fetch_size | set the JDBC fetch size |
| hibernate.jdbc.use_scrollable_resultset | enable use of JDBC2 scrollable resultsets (you only need this specify this property when using user supplied connections) |
| hibernate.jdbc.use_getGeneratedKeys | enable use of JDBC3 PreparedStatement.getGeneratedKeys() to retrieve natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+ |
| hibernate.hbm2ddl.auto | enable auto DDL export |
| hibernate.default_schema | use given schema name for unqualified tables (always optional) |
| hibernate.default_catalog | use given catalog name for unqualified tables (always optional) |
| hibernate.session_factory_name | If set, the factory attempts to bind this name to itself in the JNDI context. This name is also used to support cross JVM Session (de)serialization. |
| hibernate.transaction.manager_lookup_class | classname of org.hibernate.transaction.TransactionManagerLookup implementor |
| hibernate.transaction.factory_class | the factory to use for instantiating Transactions. (Defaults to JDBCTransactionFactory.) |
| hibernate.query.substitutions | query language token substitutions |
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringEnable automatic session close at end of transactionstatic final StringJDBC autocommit modestatic final StringSelect a custom batcher.static final StringShould versioned data be included in batching?static final Stringstatic final StringNumber of connections acquired when pool is exhaustedstatic final StringIdle time before a C3P0 pooled connection is validatedstatic final StringMaximum size of C3P0 connection poolstatic final StringMaximum size of C3P0 statement cachestatic final StringMinimum size of C3P0 connection poolstatic final StringMaximum idle time for C3P0 connection poolstatic final StringThe CacheProvider JNDI namespace, if pre-bound to JNDI.static final StringThe CacheProvider implementation classstatic final StringThe CacheProvider implementation classstatic final StringTheRegionFactoryimplementation classstatic final StringThe CacheProvider region name prefixstatic final StringEnable nullability checking.static final Stringprefix for arbitrary JDBC connection propertiesstatic final StringConnectionProvider implementor to use when obtaining connectionsstatic final StringContext scoping impl forSessionFactory.getCurrentSession()processing.static final Stringjava.sql.Datasource JNDI namestatic final StringThe default batch size for batch fetchingstatic final StringA default database catalog name to use for unqualified tablenamesstatic final StringThe EntityMode in which set the Session opened from the SessionFactory.static final StringA default database schema (owner) name to use for unqualified tablenamesstatic final StringIf none is explicitly set, default TransactionManagerLookup implementor to use for obtaining the TransactionManagerstatic final StringIf none is explicitly set, default TransactionFactory implementor to use for creating Transactionsstatic final StringHibernate SQLDialectclassstatic final StringDialectResolverclasses to register with theDialectFactorystatic final StringJDBC driver classstatic final StringEnable automatic flush during the JTA beforeCompletion() callbackstatic final StringEnable formatting of SQL logged to the consolestatic final StringEnable statistics collectionstatic final StringShould all database identifiers be quoted.static final StringAuto export/update schema using hbm2ddl tool.static final StringComma-separated names of the optional files containing SQL DML statements executed during the SessionFactory creation.static final StringJDBC transaction isolation levelstatic final StringThe jacc context id of the deploymentstatic final StringJNDI initial context class, Context.INITIAL_CONTEXT_FACTORYstatic final Stringprefix for arbitrary JNDI InitialContext propertiesstatic final StringJNDI provider URL, Context.PROVIDER_URLstatic final Stringstatic final StringMaximum depth of outer join fetchingstatic final StringEnable ordering of insert statements for the purpose of more efficient JDBC batching.static final StringEnable ordering of update statements by primary key valuestatic final StringAn XSLT resource used to generate "custom" XMLstatic final StringJDBC passwordstatic final StringMaximum number of inactive connections for Hibernate's connection poolstatic final StringWhen using pooledoptimizers, prefer interpreting the database value as the lower (lo) boundary.static final StringProxool property to configure the Proxool Provider from an already existing pool (true / false)static final StringProxool property with the Proxool pool alias to use (Required for PROXOOL_EXISTING_POOL, PROXOOL_PROPERTIES, or PROXOOL_XML)static final StringProxool/Hibernate property prefixstatic final StringProxool property to configure the Proxool Provider using a properties file (/path/to/proxool.properties)static final StringProxool property to configure the Proxool Provider using an XML (/path/to/file.xml)static final StringThe QueryCacheFactory implementation class.static final StringThe maximum number of soft references maintained bySoftLimitMRUCache.static final StringThe maximum number of strong references maintained bySoftLimitMRUCache.static final StringShould named queries be checked during startup (the default is enabled).static final StringA comma-separated list of token substitutions to use when translating a Hibernate query to SQLstatic final StringThe classname of the HQL query parser factorystatic final StringSpecifies how Hibernate should release JDBC connections.static final StringJNDI name to bind to SessionFactorystatic final StringEnable logging of generated SQL to the consolestatic final StringTheSQLExceptionConverterto use for converting SQLExceptions to Hibernate's JDBCException hierarchy.static final StringMaximum JDBC batch size.static final StringGives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed.static final StringTransactionManagerLookup implementor to use for obtaining the TransactionManagerstatic final StringTransactionFactory implementor to use for creating Transactionsstatic final StringJDBC URLstatic final StringTells the JDBC driver to attempt to retrieve row Id with the JDBC 3.0 PreparedStatement.getGeneratedKeys() method.static final Stringstatic final StringOptimize the cache for minimal puts instead of minimal getsstatic final StringEnable the query cache (disabled by default)static final StringUse bytecode libraries optimized property accessstatic final StringUse JDBC scrollable ResultSets.static final StringEnable the second-level cache (enabled by default)static final StringAdd comments to the generated SQLstatic final StringUse java.io streams to read / write binary data from / to JDBCstatic final StringEnable use of structured second-level cache entriesstatic final StringJDBC userstatic final StringJNDI name of JTA UserTransaction objectstatic final StringEnable wrapping of JDBC result sets in order to speed up column name lookups for broken JDBC drivers -
Method Summary
Modifier and TypeMethodDescriptionstatic BytecodeProviderbuildBytecodeProvider(Properties properties) static BytecodeProviderstatic PropertiesReturn System properties, extended by any properties specified in hibernate.properties.static StringisolationLevelToString(int isolation) Get the name of a JDBC transaction isolation levelstatic booleanDeprecated.Starting with 3.3 Hibernate requires JDK 1.4 or higherstatic booleanDoes this JVM's implementation ofTimestamphave a bug in which the following is true:new java.sql.Timestamp( x ).getTime() != xstatic booleanDeprecated.Starting with 3.3 Hibernate requires JDK 1.4 or higherstatic booleanDeprecated.Starting with 3.3 Hibernate requires JDK 1.4 or higherstatic booleanShould we use reflection optimization?static booleanShould we use streams to bind binary types to JDBC IN parameters?static voidverifyProperties(Properties props) Issues warnings to the user when any obsolete or renamed property names are used.
-
Field Details
-
CONNECTION_PROVIDER
ConnectionProvider implementor to use when obtaining connections- See Also:
-
DRIVER
JDBC driver class- See Also:
-
ISOLATION
JDBC transaction isolation level- See Also:
-
URL
JDBC URL- See Also:
-
USER
JDBC user- See Also:
-
PASS
JDBC password- See Also:
-
AUTOCOMMIT
JDBC autocommit mode- See Also:
-
POOL_SIZE
Maximum number of inactive connections for Hibernate's connection pool- See Also:
-
DATASOURCE
java.sql.Datasource JNDI name- See Also:
-
CONNECTION_PREFIX
prefix for arbitrary JDBC connection properties- See Also:
-
JNDI_CLASS
JNDI initial context class, Context.INITIAL_CONTEXT_FACTORY- See Also:
-
JNDI_URL
JNDI provider URL, Context.PROVIDER_URL- See Also:
-
JNDI_PREFIX
prefix for arbitrary JNDI InitialContext properties- See Also:
-
SESSION_FACTORY_NAME
JNDI name to bind to SessionFactory- See Also:
-
DIALECT
Hibernate SQLDialectclass- See Also:
-
DIALECT_RESOLVERS
DialectResolverclasses to register with theDialectFactory- See Also:
-
DEFAULT_SCHEMA
A default database schema (owner) name to use for unqualified tablenames- See Also:
-
DEFAULT_CATALOG
A default database catalog name to use for unqualified tablenames- See Also:
-
SHOW_SQL
Enable logging of generated SQL to the console- See Also:
-
FORMAT_SQL
Enable formatting of SQL logged to the console- See Also:
-
USE_SQL_COMMENTS
Add comments to the generated SQL- See Also:
-
MAX_FETCH_DEPTH
Maximum depth of outer join fetching- See Also:
-
DEFAULT_BATCH_FETCH_SIZE
The default batch size for batch fetching- See Also:
-
USE_STREAMS_FOR_BINARY
Use java.io streams to read / write binary data from / to JDBC- See Also:
-
USE_SCROLLABLE_RESULTSET
Use JDBC scrollable ResultSets. This property is only necessary when there is no ConnectionProvider, ie. the user is supplying JDBC connections.- See Also:
-
USE_GET_GENERATED_KEYS
Tells the JDBC driver to attempt to retrieve row Id with the JDBC 3.0 PreparedStatement.getGeneratedKeys() method. In general, performance will be better if this property is set to true and the underlying JDBC driver supports getGeneratedKeys().- See Also:
-
STATEMENT_FETCH_SIZE
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. If 0, JDBC driver default settings will be used.- See Also:
-
STATEMENT_BATCH_SIZE
Maximum JDBC batch size. A nonzero value enables batch updates.- See Also:
-
BATCH_STRATEGY
Select a custom batcher.- See Also:
-
BATCH_VERSIONED_DATA
Should versioned data be included in batching?- See Also:
-
OUTPUT_STYLESHEET
An XSLT resource used to generate "custom" XML- See Also:
-
C3P0_MAX_SIZE
Maximum size of C3P0 connection pool- See Also:
-
C3P0_MIN_SIZE
Minimum size of C3P0 connection pool- See Also:
-
C3P0_TIMEOUT
Maximum idle time for C3P0 connection pool- See Also:
-
C3P0_MAX_STATEMENTS
Maximum size of C3P0 statement cache- See Also:
-
C3P0_ACQUIRE_INCREMENT
Number of connections acquired when pool is exhausted- See Also:
-
C3P0_IDLE_TEST_PERIOD
Idle time before a C3P0 pooled connection is validated- See Also:
-
PROXOOL_PREFIX
Proxool/Hibernate property prefix- See Also:
-
PROXOOL_XML
Proxool property to configure the Proxool Provider using an XML (/path/to/file.xml)- See Also:
-
PROXOOL_PROPERTIES
Proxool property to configure the Proxool Provider using a properties file (/path/to/proxool.properties)- See Also:
-
PROXOOL_EXISTING_POOL
Proxool property to configure the Proxool Provider from an already existing pool (true / false)- See Also:
-
PROXOOL_POOL_ALIAS
Proxool property with the Proxool pool alias to use (Required for PROXOOL_EXISTING_POOL, PROXOOL_PROPERTIES, or PROXOOL_XML)- See Also:
-
AUTO_CLOSE_SESSION
Enable automatic session close at end of transaction- See Also:
-
FLUSH_BEFORE_COMPLETION
Enable automatic flush during the JTA beforeCompletion() callback- See Also:
-
RELEASE_CONNECTIONS
Specifies how Hibernate should release JDBC connections.- See Also:
-
CURRENT_SESSION_CONTEXT_CLASS
Context scoping impl forSessionFactory.getCurrentSession()processing.- See Also:
-
TRANSACTION_STRATEGY
TransactionFactory implementor to use for creating Transactions- See Also:
-
DEFAULT_TRANSACTION_STRATEGY
If none is explicitly set, default TransactionFactory implementor to use for creating Transactions- See Also:
-
TRANSACTION_MANAGER_STRATEGY
TransactionManagerLookup implementor to use for obtaining the TransactionManager- See Also:
-
DEFAULT_TRANSACTION_MANAGER_STRATEGY
If none is explicitly set, default TransactionManagerLookup implementor to use for obtaining the TransactionManager- See Also:
-
USER_TRANSACTION
JNDI name of JTA UserTransaction object- See Also:
-
CACHE_PROVIDER
The CacheProvider implementation class- See Also:
-
CACHE_REGION_FACTORY
TheRegionFactoryimplementation class- See Also:
-
CACHE_PROVIDER_CONFIG
The CacheProvider implementation class- See Also:
-
CACHE_NAMESPACE
The CacheProvider JNDI namespace, if pre-bound to JNDI.- See Also:
-
USE_QUERY_CACHE
Enable the query cache (disabled by default)- See Also:
-
QUERY_CACHE_FACTORY
The QueryCacheFactory implementation class.- See Also:
-
USE_SECOND_LEVEL_CACHE
Enable the second-level cache (enabled by default)- See Also:
-
USE_MINIMAL_PUTS
Optimize the cache for minimal puts instead of minimal gets- See Also:
-
CACHE_REGION_PREFIX
The CacheProvider region name prefix- See Also:
-
USE_STRUCTURED_CACHE
Enable use of structured second-level cache entries- See Also:
-
GENERATE_STATISTICS
Enable statistics collection- See Also:
-
USE_IDENTIFIER_ROLLBACK
- See Also:
-
USE_REFLECTION_OPTIMIZER
Use bytecode libraries optimized property access- See Also:
-
QUERY_TRANSLATOR
The classname of the HQL query parser factory- See Also:
-
QUERY_SUBSTITUTIONS
A comma-separated list of token substitutions to use when translating a Hibernate query to SQL- See Also:
-
QUERY_STARTUP_CHECKING
Should named queries be checked during startup (the default is enabled). Mainly intended for test environments.- See Also:
-
HBM2DDL_AUTO
Auto export/update schema using hbm2ddl tool. Valid values are update, create, create-drop and validate.- See Also:
-
HBM2DDL_IMPORT_FILES
Comma-separated names of the optional files containing SQL DML statements executed during the SessionFactory creation. File order matters, the statements of a give file are executed before the statements of the following files. These statements are only executed if the schema is created ie if hibernate.hbm2ddl.auto is set to create or create-drop. The default value is /import.sql- See Also:
-
SQL_EXCEPTION_CONVERTER
TheSQLExceptionConverterto use for converting SQLExceptions to Hibernate's JDBCException hierarchy. The default is to use the configuredDialect's preferred SQLExceptionConverter.- See Also:
-
WRAP_RESULT_SETS
Enable wrapping of JDBC result sets in order to speed up column name lookups for broken JDBC drivers- See Also:
-
ORDER_UPDATES
Enable ordering of update statements by primary key value- See Also:
-
ORDER_INSERTS
Enable ordering of insert statements for the purpose of more efficient JDBC batching.- See Also:
-
DEFAULT_ENTITY_MODE
The EntityMode in which set the Session opened from the SessionFactory.- See Also:
-
JACC_CONTEXTID
The jacc context id of the deployment- See Also:
-
GLOBALLY_QUOTED_IDENTIFIERS
Should all database identifiers be quoted.- See Also:
-
CHECK_NULLABILITY
Enable nullability checking. Raises an exception if a property marked as not-null is null. Default to false if Bean Validation is present in the classpath and Hibernate Annotations is used, true otherwise.- See Also:
-
BYTECODE_PROVIDER
- See Also:
-
JPAQL_STRICT_COMPLIANCE
- See Also:
-
PREFER_POOLED_VALUES_LO
When using pooledoptimizers, prefer interpreting the database value as the lower (lo) boundary. The default is to interpret it as the high boundary.- See Also:
-
QUERY_PLAN_CACHE_MAX_STRONG_REFERENCES
The maximum number of strong references maintained bySoftLimitMRUCache. Default is 128.- See Also:
-
QUERY_PLAN_CACHE_MAX_SOFT_REFERENCES
The maximum number of soft references maintained bySoftLimitMRUCache. Default is 2048.- See Also:
-
-
Method Details
-
verifyProperties
Issues warnings to the user when any obsolete or renamed property names are used.- Parameters:
props- The specified properties.
-
getBytecodeProvider
-
jvmHasTimestampBug
public static boolean jvmHasTimestampBug()Does this JVM's implementation ofTimestamphave a bug in which the following is true:new java.sql.Timestamp( x ).getTime() != xNOTE : IBM JDK 1.3.1 the only known JVM to exhibit this behavior.- Returns:
- True if the JVM's
Timestampimplementa
-
jvmHasJDK14Timestamp
public static boolean jvmHasJDK14Timestamp()Deprecated.Starting with 3.3 Hibernate requires JDK 1.4 or higherDoes this JVM handleTimestampin the JDK 1.4 compliant way wrt to nano rolling>- Returns:
- True if the JDK 1.4 (JDBC3) specification for
Timestampnano rolling is adhered to.
-
jvmSupportsLinkedHashCollections
public static boolean jvmSupportsLinkedHashCollections()Deprecated.Starting with 3.3 Hibernate requires JDK 1.4 or higherDoes this JVM supportLinkedHashSetandLinkedHashMap? Note, this is true for JDK 1.4 and above; hence the deprecation.- Returns:
- True if
LinkedHashSetandLinkedHashMapare available. - See Also:
-
jvmSupportsGetGeneratedKeys
public static boolean jvmSupportsGetGeneratedKeys()Deprecated.Starting with 3.3 Hibernate requires JDK 1.4 or higherDoes this JDK/JVM define the JDBCStatementinterface with a 'getGeneratedKeys' method? Note, this is true for JDK 1.4 and above; hence the deprecation.- Returns:
- True if generated keys can be retrieved via Statement; false otherwise.
- See Also:
-
useStreamsForBinary
public static boolean useStreamsForBinary()Should we use streams to bind binary types to JDBC IN parameters?- Returns:
- True if streams should be used for binary data handling; false otherwise.
- See Also:
-
useReflectionOptimizer
public static boolean useReflectionOptimizer()Should we use reflection optimization?- Returns:
- True if reflection optimization should be used; false otherwise.
- See Also:
-
getProperties
Return System properties, extended by any properties specified in hibernate.properties.- Returns:
- Properties
-
isolationLevelToString
Get the name of a JDBC transaction isolation level- Parameters:
isolation- as defined by java.sql.Connection- Returns:
- a human-readable name
- See Also:
-
buildBytecodeProvider
-