# Hibernate 6 data save problem

**URL:** <https://discourse.hibernate.org/t/hibernate-6-data-save-problem/9344>\
**Category:** Hibernate ORM\
**Created:** [April 9, 2024, 10:37am UTC](https://discourse.hibernate.org/t/hibernate-6-data-save-problem/9344 "2024-04-09T10:37:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abrar](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Abrar](https://discourse.hibernate.org/u/Abrar)\
**Post date:** [April 9, 2024, 10:37am UTC](https://discourse.hibernate.org/t/hibernate-6-data-save-problem/9344/1 "2024-04-09T10:37:29Z")

</div>

java.lang.NullPointerException: Cannot invoke “jakarta.persistence.EntityManager.persist(Object)” because “this.manager” is null  
project.dao.TestDao.dataSave(TestDao.java:38)

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 9, 2024, 12:07pm UTC](https://discourse.hibernate.org/t/hibernate-6-data-save-problem/9344/2 "2024-04-09T12:07:50Z")

</div>

How are we supposed to help you with this little information?

Is there a question you wanted to ask? Please provide information about the context in which you’re seeing this error and why you think it is related to Hibernate if you want anyone from the community to reply.

---

<div class="post-metadata">

**Author:** ![Abrar](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Abrar](https://discourse.hibernate.org/u/Abrar)\
**Post date:** [April 10, 2024, 10:22am UTC](https://discourse.hibernate.org/t/hibernate-6-data-save-problem/9344/3 "2024-04-10T10:22:48Z")

</div>

## XML

```
  <property name="packagesToScan">
        <list>
			<value>project.bn</value>
        </list>
    </property>
  
  <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="true" />
            <property name="showSql" value="true" />
        </bean>
  </property>
  
  <property name="jpaPropertyMap">
        <props>
            <!-- <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> -->                      
            <prop key="hibernate.jdbc.lob.non_contextual_creation">true</prop>  
                     
            <prop key="hibernate.connection.CharSet">utf8</prop>
            <prop key="hibernate.connection.characterEncoding">utf8</prop>
            <prop key="hibernate.connection.useUnicode">true</prop>
                            
            <prop key="connection.pool_size">1</prop>
            <prop key="current_session_context_class">thread</prop>
                 
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
                           
        </props>
    </property>   

```

```
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactoryBean" />

```

\<tx:annotation-driven /\>

```
<bean id="testBn" class="project.bn.TestBn"/>

<bean id="testDao" class="project.dao.TestDao">  
	<property name="testBn" ref="testBn" />   
</bean>  

<bean id="testController" class="project.controller.TestController"> 
	<property name="testDao" ref="testDao" />  
	<property name="testBn" ref="testBn" /> 
</bean> 

```

## DAO

@Autowired  
private TestBn testBn;

```
@PersistenceContext
private EntityManager manager;
			
@Transactional
public void dataSave (TestBn testBn) {

	manager.persist(testBn);
}

```

## Controller

@Autowired  
private TestBn testBn;

```
@Autowired
private ITestDao testDao;

@RequestMapping("/home.htm")
public String showHome() {          	 
	testBn.setBarcodeValue("Barcode Code");                        
    testDao.dataSave(testBn);

   return "home";
}

```

## interface

public interface ITestDao {  
public void dataSave (TestBn testBn);

}

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 10, 2024, 11:50am UTC](https://discourse.hibernate.org/t/hibernate-6-data-save-problem/9344/4 "2024-04-10T11:50:16Z")

</div>

Still not sure what you’re asking, but it looks like this property is null:

```java
@PersistenceContext
private EntityManager manager;

```

The annotation `@PersistenceContext` is not defined by either Hibernate or JPA, so I’m not sure how it’s supposed to work and I can’t help you with it.
