Unable to lookup JDBC datasource by JNDI - java

I am using Spring Data, Hibernate and jBoss 6.x.x.
I would like to look up at the jBoss 6.x.x the already configured jdbc datasource by JNDI.
Looking at the file standalone.xml, I have found the following entries:
<profile>
...
<datasources>
...
<datasource enabled="true" jndi-name="name_of_the_ds" pool-name="name_of_the_pool" use-java-context="true">
<connection-url>connection_uri</connection-url>
<driver>driver_name</driver>
<security>
<user-name>fake_login</user-name>
<password>fake_password</password>
</security>
</datasource>
...
</datasources>
...
</profile>
Based on this, I have written the following Spring annotation configuration
class for the data base (I am using Spring Data and Hibernate as the JPA provider)
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(basePackages = "dao.repository")
#PropertySource("classpath:application.properties")
public class DataBaseContextConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(DataBaseContextConfiguration.class);
private Database dataBase = Database.SOME_DATA_BASE;
#Value("${jpa.showSql}")
private Boolean showSql;
#Value("${name.data.source}")
private String dataSourceJndiName;
#Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() throws NamingException {
final LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(dataSource());
localContainerEntityManagerFactoryBean.setPackagesToScan(PACKAGE_WITH_DB_ENTITIES);
JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
return localContainerEntityManagerFactoryBean;
}
#Bean
public PlatformTransactionManager platformTransactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
return jpaTransactionManager;
}
public DataSource dataSource() throws NamingException {
DataSource dataSource = null;
JndiTemplate jndi = new JndiTemplate();
dataSource = (DataSource) jndi.lookup(dataSourceJndiName);
return dataSource;
}
}
The String dataSourceJndiName has the following value name_of_the_ds.
When I am trying to run simple integration test the following exception occurres:
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Related

jBPM and JPA Transaction Manager: no local transaction to join

I'm having a really hard time setting up a jBPM7 project. I'm trying to use the jBPM engine with an H2 in-memory database to make use of the Human Task Service. I've set up my data source, entity manager factory and transaction manager as below:
application.properties
...
jbpm.datasource.jdbc-url=jdbc:h2:mem:testdb
jbpm.datasource.username=sa
jbpm.datasource.password=
...
JbpmDataConfiguration.java
#Configuration
#EnableTransactionManagement
public class JbpmDataConfiguration {
#Bean(name = "jbpmDataSource")
#ConfigurationProperties(prefix = "jbpm.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "jbpmEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean jbpmEntityManagerFactory(EntityManagerFactoryBuilder builder, #Qualifier("jbpmDataSource") DataSource dataSource) {
Map<String, String> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", "create");
return builder.dataSource(dataSource)
.mappingResources("META-INF/Taskorm.xml")
.packages("org.jbpm.services.task.impl.model")
.persistenceUnit("jbpm-persistence-unit")
.properties(properties)
.build();
}
#Bean(name = "jbpmTransactionManager")
public JpaTransactionManager jbpmTransactionManager(#Qualifier("jbpmEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
return jpaTransactionManager;
}
}
In my resources folder I have a kmodule.xml in resources/META-INF/. All my .bpmn files are in resources/com/mydomain/flow/
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="kbase" packages="com.mydomain.flow" />
</kmodule>
I am then creating a runtime engine using the following:
#Configuration
public class MyRuntimeEngine {
#Autowired
#Qualifier("jbpmEntityManagerFactory")
private EntityManagerFactory entityManagerFactory;
#Autowired
#Qualifier("jbpmTransactionManager")
private JpaTransactionManager transactionManager;
#Bean
public RuntimeManager runtimeManager() {
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieBase kieBase = kieContainer.getKieBase("kbase");
RuntimeEnvironmentBuilder runtimeEnvironmentBuilder = RuntimeEnvironmentBuilder.Factory.get()
.newDefaultInMemoryBuilder()
.entityManagerFactory(entityManagerFactory)
.addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, transactionManager);
RuntimeEnvironment runtimeEnvironment = runtimeEnvironmentBuilder.knowledgeBase(kieBase).get();
return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(runtimeEnvironment);
}
}
I am autowiring the RuntimeManager bean into another configuration class so I can configure global variables and work item handlers. This then exposes a KieSession bean once it's done. To then start a process, I am autowiring the KieSession into one of my controllers and calling startProcess:
kieSession.startProcess(processName, processVariables);
which results in the following error:
javax.persistence.TransactionRequiredException: No local transaction to join
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:391) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:333) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at com.sun.proxy.$Proxy160.joinTransaction(Unknown Source) ~[na:na]
at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.joinTransaction(JPAWorkingMemoryDbLogger.java:318) ~[jbpm-audit-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.persist(JPAWorkingMemoryDbLogger.java:246) ~[jbpm-audit-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.afterVariableChanged(JPAWorkingMemoryDbLogger.java:133) ~[jbpm-audit-7.22.0.Final.jar:7.22.0.Final]
at org.drools.core.event.ProcessEventSupport.fireAfterVariableChanged(ProcessEventSupport.java:155) ~[drools-core-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.context.variable.VariableScopeInstance.setVariable(VariableScopeInstance.java:114) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.AbstractProcessInstanceFactory.createProcessInstance(AbstractProcessInstanceFactory.java:59) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:260) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:242) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:200) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:190) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:185) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
...
How do I properly configure the transaction manager to work with jBPM?
I am also having same trouble in setting up JBPM 7.x version. Were you able to get JBPM running with JPA transaction manager...from the official documentation it seems that we need external transaction manager implementations like Narayanan or bitronix if JBPM needs to be used in embedded mode

Configure Hibernate models discovery in Spring

I want to configure Spring with Hibernate 5 and JNDI using this code:
#Configuration
#EnableTransactionManagement
public class ContextDatasource {
#Bean
public LocalSessionFactoryBean sessionFactory() throws NamingException {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan("org.database.models");
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public PlatformTransactionManager hibernateTransactionManager() throws NamingException {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
private final Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty(
"hibernate.show_sql", "true");
hibernateProperties.setProperty(
"hibernate.format_sql", "true");
hibernateProperties.setProperty(
"hibernate.hbm2ddl.auto", "create-drop");
hibernateProperties.setProperty(
"hibernate.dialect", "org.hibernate.dialect.MariaDBDialect");
return hibernateProperties;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory()
throws NamingException {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
return em;
}
#Bean
public DataSource dataSource() throws NamingException {
return (DataSource) new JndiTemplate().lookup("java:/global/production_gateway");
}
#Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
}
But when I deploy the code I get error. Looks like I have to add another XML configuration file:
Caused by: java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}
Hibernate models are located in a remote jar under Java package org.database.models How I can map them using Java code?
May you need to add dependencies to your pom file, if you use maven
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
To prevent hibernate persistence.xml usage, you must define on LocalContainerEntityManagerFactoryBean the packages to scan entity from.
emf.setPackagesToScan(myPackagesToScan);

Jhipster Multi-tenancy with Hibernate Second Level Caching

I've been attempting to turn my JHipster generated application into a multi-tenancy app using this - http://jannatconsulting.com/blog/?p=41 blog post as a base.
I've run into a problem with second level caching. Spring boot appears to correctly detect and set up:
DatabaseConfiguration.java
#Configuration
#EnableConfigurationProperties(JpaProperties.class)
#EnableJpaRepositories(
entityManagerFactoryRef = "masterEntityManager",
transactionManagerRef = "masterTransactionManager",
basePackages = {"com.quadrimular.nts.helium.repository.master"})
#EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
#EnableTransactionManagement
#EnableElasticsearchRepositories("com.quadrimular.nts.helium.repository.search")
public class DatabaseConfiguration {
#Inject
private Environment env;
#Autowired(required = false)
private MetricRegistry metricRegistry;
#Inject
private DataSourceProperties datasourceProperties;
#Inject
private JHipsterProperties jhipsterProperties;
#Inject
private JpaProperties jpaProperties;
#Inject
private DataSource dataSource;
#Bean(destroyMethod = "close")
#ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
log.debug("Configuring Master Datasource");
if (dataSourceProperties.getUrl() == null) {
log.error("Your database connection pool configuration is incorrect! The application" +
" cannot start. Please check your Spring profile, current profiles are: {}",
Arrays.toString(env.getActiveProfiles()));
throw new ApplicationContextException("Database connection pool is not configured correctly");
}
HikariConfig config = new HikariConfig();
config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
config.addDataSourceProperty("url", dataSourceProperties.getUrl());
if (dataSourceProperties.getUsername() != null) {
config.addDataSourceProperty("user", dataSourceProperties.getUsername());
} else {
config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
}
if (dataSourceProperties.getPassword() != null) {
config.addDataSourceProperty("password", dataSourceProperties.getPassword());
} else {
config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
}
//MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
}
if (metricRegistry != null) {
config.setMetricRegistry(metricRegistry);
}
return new HikariDataSource(config);
}
#Bean(name = "masterEntityManager")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource(datasourceProperties, jhipsterProperties));
em.setPackagesToScan(new String[]{"com.quadrimular.nts.helium.domain.master"});
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalJpaProperties());
em.setPersistenceUnitName("master");
return em;
}
private Properties additionalJpaProperties() {
Properties properties = new Properties();
for (Map.Entry<String, String> entry : jpaProperties.getHibernateProperties(dataSource).entrySet()) {
properties.setProperty(entry.getKey(), entry.getValue());
}
return properties;
}
#Bean(name = "masterTransactionManager")
public JpaTransactionManager transactionManager(EntityManagerFactory masterEntityManager){
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(masterEntityManager);
return transactionManager;
}
}
When spring tries to configure:
MultiTenancyJPAConfiguration.java
#Configuration
#EnableConfigurationProperties(JpaProperties.class)
#EnableJpaRepositories(
entityManagerFactoryRef = "tenantEntityManager",
transactionManagerRef = "tenantTransactionManager",
basePackages = {"com.quadrimular.nts.helium.repository.tenant"})
#EnableTransactionManagement
public class MultiTenancyJpaConfiguration {
#Bean(name = "tenantEntityManager")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider connectionProvider,
CurrentTenantIdentifierResolver tenantResolver) {
LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
emfBean.setDataSource(dataSource);
emfBean.setPackagesToScan("com.quadrimular.nts.helium.domain.tenant");
emfBean.setJpaVendorAdapter(jpaVendorAdapter());
Map<String, Object> properties = new HashMap<>();
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, connectionProvider);
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantResolver);
properties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
emfBean.setJpaPropertyMap(properties);
return emfBean;
}
#Bean(name = "tenantTransactionManager")
public JpaTransactionManager transactionManager(EntityManagerFactory tenantEntityManager){
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(tenantEntityManager);
return transactionManager;
}
}
I'm getting this in my trace:
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
I have all the required properties defined in my application-dev.yml
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
It appears that it's being read and used correctly by spring boot for my DatabaseConfiguration.java. I can't work out why it's not detecting the property file. If I try to disable the cache by setting:
hibernate.cache.use_second_level_cache: false
DatabaseConfiguration.java detects and behaves accordingly however MultiTenancyJPAConfiguration.java still throws the same exception.
Am I missing something obvious?
The answer is to actually set the jpa property values on the entity manager. I'm not sure how I overlooked this; I thought that somehow they were already set.
Firstly I injected the main datasource and the jpa properties object provided by spring boot if I'm not mistaken.
MultiTenancyJPAConfiguration.java
#Inject
private JpaProperties jpaProperties;
#Inject
private DataSource dataSource;
I then set the values using the same method used in DatabaseConfiguration.java
MultiTenancyJPAConfiguration.java
#Bean(name = "tenantEntityManager")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider connectionProvider,
CurrentTenantIdentifierResolver tenantResolver) {
LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
emfBean.setDataSource(dataSource);
emfBean.setPackagesToScan("com.quadrimular.nts.helium.domain.tenant");
emfBean.setJpaVendorAdapter(jpaVendorAdapter());
Map<String, Object> properties = new HashMap<>();
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, connectionProvider);
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantResolver);
properties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
emfBean.setJpaPropertyMap(properties);
emfBean.setJpaProperties(additionalJpaProperties());
return emfBean;
}
private Properties additionalJpaProperties() {
Properties properties = new Properties();
for (Map.Entry<String, String> entry : jpaProperties.getHibernateProperties(dataSource).entrySet()) {
properties.setProperty(entry.getKey(), entry.getValue());
}
return properties;
}
Using the method additionalJpaProperties() to get all the hibernate jpa properties for my main datasource. I then set the hibernate property map properties after the hard coded ones. Clearly not the cleanest solution I plan to set all jpa values from the .yml file.

Connect to mySQL via GlassFish connection pool

I'm having this error while trying to connect to mySQL database:
No object bound to name java:comp/env/jdbc/mySql
This is my configuration class:
#Configuration
#EnableTransactionManagement
#ComponentScan({ "org.onmyown.config" })
#PropertySource(value = { "classpath:application.properties" })
public class HibernateConfiguration {
#Autowired
private Environment environment;
#Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "org.onmyown" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public DataSource dataSource() {
DataSource dataSource = null;
try {
Context initialContext = new InitialContext();
Context environmentContext = (Context)initialContext.lookup("java:comp/env");
dataSource = (DataSource) environmentContext.lookup("jdbc/mySql");
} catch (NamingException e) {
e.printStackTrace();
}
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
return properties;
}
#Bean
#Autowired
public HibernateTransactionManager transactionManager(SessionFactory s) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(s);
return txManager;
}
}
I can ping from GlassFish just fine. I put all the properties I need (I think). My friend did this configuration with Derby database and it works. Is there any difference?
#edit
I 'fixed' something. I added web.xml, everything is here:
https://github.com/afterlook/SpringMVC
The problem now is that the application doesn't really care that i put mySql as a data source. It searches for DerbyPool which is one of the defaults in GlassFish. Any idea why?
The problem you posted originaly tries to use a datasource that is looked up using JNDI with the key comp/env/jdbc/mySql and this is not configured.
If you want to use a connection pool of Glasfish, you have to configure Glasfish so it creates that pool and publishes it as a JNDI component with the key comp/env/jdbc/mySql
mysql glasfish shows how this is done.
With your fix you commented the JNDI code out, instead you set the connection url from a property.
db.url=jdbc:mysql://localhost:3306/app
without additional configuration, this seems to point to the Glasfish default connection pool using the derby db.
If you want to use the Glasfish connection pool :
Configure Glasfish to crate that pool using mysql as described in the linked document.
You will configure url,user,password for the Glsfish connection pool, so I think you dont have to provide it in the spring config again. Take the datasource as you get it from the JNDI lookup.
Revert your fix that commented out the JNDI lookup.
Your code should look like this :
#Bean
public DataSource dataSource() {
DataSource dataSource = null;
try {
Context initialContext = new InitialContext();
Context environmentContext = (Context)initialContext.lookup("java:comp/env");
dataSource = (DataSource) environmentContext.lookup("jdbc/mySql");
} catch (NamingException e) {
e.printStackTrace();
}*/
return dataSource;
}

Play Framework evolutions not working with Spring/Hibernate

I am using java-play-spring template (obtainable here: https://github.com/jamesward/play-java-spring#master )and currently I am trying to write some evolutions for it.
I am putting my script:
# --- !Ups
CREATE TABLE accounts
(
accountid INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
clientid INT NOT NULL,
credit DECIMAL(13,2)
);
# --- !Downs
drop table accounts;
into conf/evolutions/default/1.sql. Unfortunatelly, after application starts, nothing happens. I suppose that it may be Spring/Hibernate fault, so i disabled Hibernate validation:
#Configuration
#EnableTransactionManagement
public class DataConfig {
#Bean
public EntityManagerFactory entityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setShowSql(true);
vendorAdapter.setGenerateDdl(false);
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPackagesToScan("models");
entityManagerFactory.setJpaVendorAdapter(vendorAdapter);
entityManagerFactory.setDataSource(dataSource());
entityManagerFactory.setValidationMode(ValidationMode.NONE);
entityManagerFactory.afterPropertiesSet();
return entityManagerFactory.getObject();
}
#Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager(entityManagerFactory());
return transactionManager;
}
#Bean
public DataSource dataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(Play.application().configuration().getString("db.default.driver"));
dataSource.setUrl(Play.application().configuration().getString("db.default.url"));
dataSource.setUsername(Play.application().configuration().getString("db.default.user"));
dataSource.setPassword(Play.application().configuration().getString("db.default.password"));
return dataSource;
}
}
But this didn't help. I have also added
play.modules.evolutions.enabled=true
To my application.conf. This does not help too.
Does anyone has any ideas what may be wrong?

Categories

Resources