Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Pointer Exception Entity Manager
    primarykey
    data
    text
    <p>I am getting a Null Pointer exception when i try to persist and Account. Turns out the <code>entityManager</code> is null but I can't figure out why. Here is the relevant code, any ideas? I have tried to do </p> <pre><code>package com.test.bank2.account; import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Transactional public class AccountRepositoryImpl implements AccountRepository{ @PersistenceContext(unitName = "entityManagerFactory") private EntityManager entityManager; @Override public void save(Account account) { entityManager.persist(account); } } </code></pre> <p>and the config:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt; &lt;jdbc:embedded-database id="dataSource"&gt; &lt;jdbc:script location="classpath:setup.sql"/&gt; &lt;/jdbc:embedded-database&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="packagesToScan" value="com.test.bank2" /&gt; &lt;property name="jpaPropertyMap"&gt; &lt;map&gt; &lt;entry key="eclipselink.weaving" value="false"/&gt; &lt;entry key="eclipselink.ddl-generation" value="create-tables"/&gt; &lt;entry key="eclipselink.target-database" value="org.eclipse.persistence.platform.database.HSQLPlatform"/&gt; &lt;/map&gt; &lt;/property&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" &gt; &lt;property name="databasePlatform" value="org.eclipse.persistence.platform.database.HSQLPlatform" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; &lt;/beans&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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