Am 11.10.13 12:55, schrieb Dmitry Gusev:
Have you read this?
http://tapestry.apache.org/integrating-with-jpa.html
You should @Inject EntityManager, if you do things right you won't have to
create EntityManager instances yourself.
Also, saying that you have NPE, it would be nice if you provide us a
stacktrace.
On Fri, Oct 11, 2013 at 2:48 PM, Andreas Ernst <a...@ae-online.de> wrote:
Hi,
i am playing with JPA, but there is no useful information about that. A
simple example to display a database table.
The entities class is in the right package entities. I did not added
something to the AppModule class. The persistence.xml exists.
Customer.tml
<html t:type="layout" title="Customer"
xmlns:t="http://tapestry.**apache.org/schema/tapestry_5_**3.xsd<http://tapestry.apache.org/schema/tapestry_5_3.xsd>
"
xmlns:p="tapestry:parameter">
<table t:type="grid" source="customers"/>
</html>
Customers.class
public class Customers {
@Property
private Customer customer;
private EntityManagerFactory factory;
private EntityManager entityManager;
@Inject
private Logger logger;
@Inject
private BeanModelSource beanModelSource;
@Inject
private Messages messages;
@Log
public List<Customers> getCustomers() {
factory = Persistence.**createEntityManagerFactory("**
de.aeits_TapestryWeb_war_1.0-**SNAPSHOTPU");
entityManager = factory.createEntityManager();
return entityManager.**createNamedQuery("Customer.**
findAll").getResultList();
}
}
What about the DAO and DAOImpl there are no informations how to use this
classes with a simple query page.
In all docus i found only
'entityManager.**createNamedQuery("Customer.**findAll").getResultList();'
is needed, but i get a null pointer expection.
Yes, i read that.
public class Customers {
@Property
private Customer customer;
@Inject
private EntityManager entityManager;
public List<Customers> getCustomers() {
return
entityManager.createNamedQuery("Customer.findAll").getResultList();
}
}
java.lang.RuntimeException: Unable to locate a single EntityManager. You
must provide the persistence unit name as defined in the persistence.xml
using the @PersistenceContext annotation.
at
org.apache.tapestry5.internal.jpa.JpaInternalUtils.getEntityManager(JpaInternalUtils.java:92)
at
org.apache.tapestry5.internal.jpa.EntityManagerObjectProvider$1.createObject(EntityManagerObjectProvider.java:62)
--
ae | Andreas Ernst | IT Spektrum
Postfach 5, 65612 Beselich
Schupbacher Str. 32, 65614 Beselich, Germany
Tel: +49-6484-91002 Fax: +49-6484-91003
a...@ae-online.de | www.ae-online.de
www.tachyon-online.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org