I have an entity class(Buyer) built automatically from database table, it has all the setter and getter. I also added a JSF managed Bean(BuyerBean) and an entitymanager in it.
@ManagedBean
@RequestScoped
public class BuyerBean {
private EntityManager entitymanager;
public BuyerBean() {
}
public void init(){
entitymanager=Persistence.createEntityManagerFactory("WebApplication3").createEntityManager();
}
public void newrec(){
entitymanager.getTransaction().begin();
Buyer b =new Buyer();
b.setBuyerId(66);
entitymanager.persist(b);
entitymanager.getTransaction().commit();
}
}
And my JFS is like this, very simple just for testing:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="click 1" action="#{buyerBean.newrec()}"/>
</h:form>
</h:body>
</html>
I just get this error every time n my browser: java.lang.NullPointerException
is something wrong with my initiator? if there is, please write the piece of code