Hi Guys
I need a problem to migrate from Hibernate 3 to Hibernate 4
I using the Configuration to get SessionFactory
Before I using the following code.
Code:
Configuration conf = new Configuration();
conf.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
conf.setProperty("hibernate.connection.release_mode", "after_statement");
conf.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
conf.setProperty("hibernate.connection.datasource", "java:jboss/datasource/optimuslabsDS");
conf.setProperty("hibernate.format_sql", hibernateFormatSql.toString());
conf.setProperty("hibernate.show_sql", hibernateShowSql.toString());
// conf.setProperty("hibernate.hbm2ddl.auto", "update");
conf.setProperty("hibernate.default_schema", schemaName);
//Hibernate 3.x
conf.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JTATransactionFactory");
conf.setProperty("hibernate.transaction.manager_lookup_class", "br.com.optimuslabs.infra.persistence.JBoss7TransactionManagerLookup");
conf.setProperty("hibernate.transaction.flush_before_completion", "true");
conf.setProperty("hibernate.current_session_context_class", "jta");
conf.setProperty("jta.UserTransaction", "java:module/UserTransaction");
for ( Class<?> c : this.jpaMappedClasses ){
conf.addAnnotatedClass(c);
}
conf.addPackage("br.com.optimuslabs.entity"); //Le o package-info.java
conf.buildSessionFactory();
Now I try the different forms.
Code:
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder();
serviceRegistryBuilder
.applySetting(AvailableSettings.DIALECT, "org.hibernate.dialect.PostgreSQL82Dialect")
.applySetting(AvailableSettings.RELEASE_CONNECTIONS, "after_statement")
.applySetting(AvailableSettings.DRIVER, "org.postgresql.Driver")
.applySetting(AvailableSettings.DATASOURCE, "java:jboss/datasource/optimuslabsDS")
.applySetting(AvailableSettings.TRANSACTION_STRATEGY, "org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory")
.applySetting(AvailableSettings.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform")
.applySetting(AvailableSettings.FLUSH_BEFORE_COMPLETION, "true")
.applySetting(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "jta");
Configuration conf = new Configuration();
conf.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
conf.setProperty("hibernate.connection.release_mode", "after_statement");
conf.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
conf.setProperty("hibernate.connection.datasource", "java:jboss/datasource/optimuslabsDS");
conf.setProperty("hibernate.format_sql", hibernateFormatSql.toString());
conf.setProperty("hibernate.show_sql", hibernateShowSql.toString());
conf.setProperty("hibernate.default_schema", schemaName);
conf.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JTATransactionFactory");
conf.setProperty("hibernate.transaction.flush_before_completion", "true");
conf.setProperty("hibernate.current_session_context_class", "jta");
conf.setProperty("jta.UserTransaction", "java:module/UserTransaction");
conf.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
I can get the SessionFactory.
But When I save or insert this data the transaction is not commited and data is not persisted.
I'm not able to find the problem.
I need the help from community.
I too try using only ServiceRegistryBuilder and MetadataSources to get a ssesionFactory.
But in this case i get the Indexer class problem.
Code:
MetadataSources metadataSources = new MetadataSources( serviceRegistryBuilder.buildServiceRegistry() );
return metadataSources
.getMetadataBuilder()
.buildMetadata();