Hibernate 6 data save problem

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

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.

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);

}

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

@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.