Ceci est mon premier post, donc si ce n'est pas compréhensible, s'il vous plaît n'hésitez pas à demander.jboss 6.1.0.final gwt et ejb combinaison
J'essaie de développer une application gwt qui utilise mes propres classes ejb à partir d'un projet externe. Mon ServiceImpl atteint l'ejb, comme requis, mais je ne suis pas en mesure d'utiliser l'injection comme il me semble. Dans ma classe ejb, j'appelle une fonction pour créer ma base de données de test avec des données factices. Pour cela (et plus tard pour toutes les demandes bien sûr) je voulais injecter un EntityManager. Ceci est fait dans mon HomeBase Base-Class. le problème: Le entityManager peut ne pas être initialisé. Je tryed les deux annotations:
@PersistenceUnit(unitName = "sung.app.kylintv.ejb")
protected EntityManagerFactory entityManagerFactory;
protected EntityManager entityManager = entityManagerFactory.createEntityManager();
ainsi, comme:
@PersistenceContext(unitName="sung.app.kylintv.ejb")
protected EntityManager entityManager;
Je suis en jBoss 6.1.0.Final, GWT 2.4 Serverside appeler mon ejb-fonction. JBoss démarre correctement, ne montrant aucune erreur. Cependant, lorsque vous appelez la fonction que je reçois ce message d'erreur:
Caused by: javax.ejb.EJBException: java.lang.NullPointerException
...
Caused by: java.lang.NullPointerException
at sung.app.kylintv.HomeBase.<init>(HomeBase.java:28) [:]
at sung.app.kylintv.product.ProductHome.<init>(ProductHome.java:35) [:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.6.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [:1.6.0_25]
at
Par débogage la fonction que je trouve le entityManager à NULL. Comment puis-je faire fonctionner l'injection? Ou est-ce que je prends une mauvaise approche à ce sujet?
Pour plus d'informations, si nécessaire: code:
package sung.app.kylintv.gwt.server;
import javax.ejb.EJB;
import sung.app.kylintv.gwt.client.DatabaseBuilderService;
import sung.app.kylintv.product.Product;
import sung.app.kylintv.product.ProductHome;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class DatabaseBuilderServiceImpl extends RemoteServiceServlet implements DatabaseBuilderService
{
@EJB(mappedName = "sung/app/kylintv/product")
private transient Product product;
@Override
public boolean createDefaultDatabaseEntries()
{
return product.createTestEntry();
}
}
La classe initiée (à travers l'interface) ProductHome:
@Stateless(name="Product")
@Local(Product.class)
public class ProductHome extends HomeBase<ProductEntity> implements Serializable, Product
{
@EJB
protected Option sessionOption;
@TransactionAttribute(REQUIRED)
public boolean createTestEntry()
{
try
{
System.out.println("TEST creating Data BEGIN");
ProductEntity currentProduct = new ProductEntity();
// ++++ fill FIRST product ++++
currentProduct.setName("bo_product_europe_basic_name");
currentProduct.setDescription("bo_product_europe_basic_description");
getEntityManager().persist(currentProduct); **<- HERE THE ERROR OCCURS**
... **For better overview I removed the further object-creation**
}
catch(Exception e)
{
//print out an error message and return false
System.out.println(e.getCause().getMessage());
return false;
}
return true;
}
}
Le HomeBase étendu:
public abstract class HomeBase<T>
{
@PersistenceUnit(unitName = "sung.app.kylintv.ejb")
protected EntityManagerFactory entityManagerFactory;
private EntityManager entityManager = entityManagerFactory.createEntityManager();
// @PersistenceContext(unitName = "sung_app_kylintv")
// protected EntityManager entityManager;
//
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public EntityManager getEntityManager() {
return entityManager;
}
}
... sérieux? Essayez de réduire la taille de la question pour moins de downvotes et peut-être même une réponse. –
désolé pour cela, j'ai essayé de rendre la question plus lisible, en déplaçant le code ci-dessous et en supprimant une partie. Les premières lignes devraient maintenant montrer mon problème. – Norman