About
persistence.properties are database and JPA provider specific.
Articles Related
Configuration
You can configure a properties (such as database connections) using:
- a properties file,
- or programmatically.
Properties file
final Properties persistenceProperties = new Properties();
InputStream is = null;
try {
is = getClass().getClassLoader().getResourceAsStream("persistence.properties");
persistenceProperties.load(is);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignored) {
}
}
}
entityManagerFactory = Persistence.createEntityManagerFactory("generated", persistenceProperties);
Programmatically
Map props = new HashMap();
props.put(PersistenceUnitProperties.JDBC_USER, "user-name");
props.put(PersistenceUnitProperties.JDBC_PASSWORD, "password");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu-name", props);
JPA Providers
Eclipselink
- javax.persistence.transactionType - Standard JPA PersistenceUnitTransactionType property, “JTA” or “RESOURCE_LOCAL”.
- javax.persistence.jtaDataSource - Standard JPA JTA DataSource name.
- javax.persistence.nonJtaDataSource - Standard JPA non-JTA DataSource name.
- javax.persistence.jdbc.driver“ - Standard JPA 2.0 JDBC driver class name for JSE deployments (was “eclipselink.jdbc.driver” in EclipseLink 1.1)
- javax.persistence.jdbc.url - Standard JPA 2.0 JDBC URL for JSE deployments (was “eclipselink.jdbc.url” in EclipseLink 1.1).
- javax.persistence.jdbc.user - Standard JPA 2.0 database user for JSE deployments (was “eclipselink.jdbc.user” in EclipseLink 1.1).
- javax.persistence.jdbc.password - Standard JPA 2.0 database password for JSE deployments (was “eclipselink.jdbc.password” in EclipseLink 1.1).
See : Class PersistenceUnitProperties for a list of all properties.
Hibernate
Most important Hibernate JDBC properties
- connection.driver_class, connection.url, connection.username and connection.password property define the JDBC connection information.
- hibernate.connection.pool_size
hibernate.connection.driver_class=oracle.jdbc.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@//localhost:1521/orcl.HotITem.local
hibernate.connection.username=test
hibernate.connection.password=test
hibernate.hbm2ddl.auto=create-drop
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
hibernate.jdbc.batch_size=0
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
The hbm2ddl.auto property enables automatic generation of database schemas directly into the database.
Note the hibernate.hbm2ddl.auto=create-drop property in the list above instructs Hibernate to initalize the database. This feature is extremely useful for testing as you don't have to take care of the database schema, JPA provider will do it for you. But don't forget to remove this setting from productional configurations or you may loose or corrupt your data if you forget it.
Toplink
Ter info:
toplink.jdbc.driver=oracle.jdbc.OracleDriver
toplink.jdbc.url=jdbc:oracle:thin:@//localhost:1521/orcl.HotITem.local
toplink.jdbc.user=test
toplink.jdbc.password=test
toplink.ddl-generation=create-tables
toplink.target-database=oracle.toplink.essentials.platform.database.oracle.OraclePlatform
toplink.create-ddl-jdbc-file-name=target/test-database/create.ddl
toplink.drop-ddl-jdbc-file-name=target/test-database/drop.ddl
toplink.logging.level=ALL