Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In my application I didn't implement TransactionManagerConfigurer interface. I use next code to configure JPA (with Hibernate implementation). You can do the same in your configuration class.</p> <pre><code> @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() { LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setDataSource(dataSource()); factoryBean.setPackagesToScan(new String[] {"com.dimasco.springjpa.domain"}); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setShowSql(true); //vendorAdapter.setGenerateDdl(generateDdl) factoryBean.setJpaVendorAdapter(vendorAdapter); Properties additionalProperties = new Properties(); additionalProperties.put("hibernate.hbm2ddl.auto", "update"); factoryBean.setJpaProperties(additionalProperties); return factoryBean; } @Bean public DataSource dataSource() { final ComboPooledDataSource dataSource = new ComboPooledDataSource(); try { dataSource.setDriverClass(driverClass); } catch (PropertyVetoException e) { throw new RuntimeException(e); } dataSource.setJdbcUrl(jdbcUrl); dataSource.setUser(user); dataSource.setPassword(password); dataSource.setMinPoolSize(3); dataSource.setMaxPoolSize(15); dataSource.setDebugUnreturnedConnectionStackTraces(true); return dataSource; } @Bean public PlatformTransactionManager transactionManager() { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject()); return transactionManager; } @Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){ return new PersistenceExceptionTranslationPostProcessor(); } </code></pre> <p>Hope this will help you)</p> <p><strong>EDIT:</strong></p> <p>You can get datasource using JNDI lookup:</p> <pre><code>@Bean public DataSource dataSource() throws Exception { Context ctx = new InitialContext(); return (DataSource) ctx.lookup("java:comp/env/jdbc/datasource"); } </code></pre> <p>More details you can find <a href="http://www.swiftmind.com/de/2011/06/22/spring-3-1-m2-testing-with-configuration-classes-and-profiles/">in this article</a>. There is example with JndiDatasourceConfig class.</p> <p><strong>EDIT 2:</strong> I ahve persistence.xml in my project, but it is empty:</p> <pre><code>&lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt; &lt;persistence-unit name="JPA_And_Spring_Test"&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>And I didn't specify any persistent unit name in my java configuration.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload