How to initialize EntytyItem and create empty form to enter new data.

I would like to use JPAContainer addon and use many-to-many JPAContainer’s Editor.

If I get Bill from database with
final EntityItem billEntityItem = billContainer.getItem(1); (ID of bill is 1 for this example).
then JPA create Form automaticaly.

You can see pictrue ().

You can see pictrue ().

This works OK.

public void init() {
  
    final JPAContainer<Bill> billContainer = JPAContainerFactory.make( Bill.class, "TestJPA");
    final EntityItem<Bill> billEntityItem = billContainer.getItem(1); // existed data from database Bill with PK = 1
    
    billForm.setCaption("Bill Editor");
    billForm.setWriteThrough(false); // Enable buffering
    billForm.setEnabled(false);
    
    billForm.setFormFieldFactory(new FieldFactory());
    billForm.setItemDataSource( billEntityItem );
    billForm.setEnabled(t ru e);
    
    setWidth("80%");
    addComponent( billForm );

}

My problem is . How do I create(initializate) new EntityItem to prepare for new form.
I would like get form for enter complete new Bill data.

If I have change kode to I don’t get Form for entering data for new bill but I get NullPointerException:
What should I do ?

final JPAContainer<Bill> billContainer = JPAContainerFactory.make( Bill.class, "TestJPA");
    
    final EntityItem<Bill> billEntityItem = billContainer.createEntityItem( new Bill() ); // ze obstojec tracun
    System.out.println( billEntityItem );
    		
    billForm.setCaption("Bill Editor");
    billForm.setWriteThrough(false); // Enable buffering
    billForm.setEnabled(false);
    
    billForm.setFormFieldFactory(new FieldFactory());
    billForm.setItemDataSource( billEntityItem );
    billForm.setEnabled(true);
    
    setWidth("80%");
    addComponent( billForm );
}

[color=#ff0000]
entities.Bill@5688147b
2012-08-24 10:59:14,399 ERROR [Application]
Terminal error:
java.lang.NullPointerException
at com.vaadin.addon.jpacontainer.fieldfactory.MasterDetailEditor.(MasterDetailEditor.java:61)
at com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory.createOneToManyField(FieldFactory.java:496)
at com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory.createJPAContainerBackedField(FieldFactory.java:395)
at com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory.createField(FieldFactory.java:216)
at com.vaadin.ui.Form.setItemDataSource(Form.java:767)
at com.vaadin.ui.Form.setItemDataSource(Form.java:718)
at com.example.testjpavaadin.editor.BillProductrEditorWindow.init(BillProductrEditorWindow.java:49)
at com.example.testjpavaadin.editor.BillProductrEditorWindow.(BillProductrEditorWindow.java:27)
at com.example.testjpavaadin.TestjpavaadinApplication$7.menuSelected(TestjpavaadinApplication.java:92)
at com.vaadin.ui.MenuBar.changeVariables(MenuBar.java:197)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:730)
at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:48)
at org.apache.geronimo.tomcat.valve.ProtectedTargetValve.invoke(ProtectedTargetValve.java:53)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:243)
at org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:373)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)

[/color]

I’m having the exact same issue. I want to create a new user using a form

User blancUser = new User(); EntityItem<User> newUser = ds_users.createEntityItem(blancUser); final Form editUserForm = new Form(); FieldFactory fieldFactory = new FieldFactory(); editUserForm.setFormFieldFactory(fieldFactory); editUserForm.setItemDataSource(newUser); ... Line 6 creates a NullPointerException:
2014-08-26T17:34:42.890+0200|Severe: java.lang.NullPointerException
at com.vaadin.addon.jpacontainer.fieldfactory.MasterDetailEditor.(MasterDetailEditor.java:76)
at com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory.createOneToManyField(FieldFactory.java:499)

What is the correct way to create a new database entry using a form?