cancel
Showing results for 
Search instead for 
Did you mean: 

JPA EntityManager Injection Throws NullPointerException

Former Member
0 Kudos

Hi,

I'm not sure which part of my application is most relevant to my question or the exception which occurs -- please point out to me what information is needed.

I'm attempting to deploy a web service, which I implement as an EJB. For persistence purposes I'm using JPA and the system database, a MaxDB. Therefore my project uses a dictionary project, a connection to which is set up in my EJB project's JPA settings. I design the entities that I would like to persist to the database as Java classes and use annotations to configure the mapping. Thus far I think everything should be fine.

When finished designing the entities I use the EJB project's context menu to "JPA Tools > Generate DDL" in order to create the corresponding tables in the dictionary project. This part is what I'm not sure of and on which I can't find much information, as it seems that the "Generate DDL" part is not part of the default Dali tools. The problem I see here, is that the Join Table I'm "configuring" using annotations, is not created. Therefore I create it manually using the Dictionary Explorer view. Furthermore I use the Dictionary Explorer view to create an archive of the dictionary project and deploy it, prior to deploying the EJB/EAR project.

The following is the beginning and the end of the error message that is thrown:

[EXCEPTION]. {0}#1#javax.ejb.EJBException: Exception in getMethodReady() for stateless bean sap.com/MyEAR*annotation|MyEJB.jar*annotation|MyPortTypeImplBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: java.lang.NullPointerException
com.sap.engine.services.ejb3.util.pool.PoolException: java.lang.NullPointerException
    at com.sap.engine.services.ejb3.util.pool.ContainerPool.translate(ContainerPool.java:288)
    at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.doResizeOneStepUp(ContainerPoolImpl.java:378)
    at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.ensureNotEmpty(ContainerPoolImpl.java:342)
    at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.pop(ContainerPoolImpl.java:309)
    at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager.getMethodReady(StatelessInstanceLifecycleManager.java:64)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke(Interceptors_StatelessInstanceGetter.java:14)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:21)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:16)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177)
    at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:133)
    at com.sap.engine.services.ejb3.webservice.impl.DefaultImplementationContainer.invokeMethod(DefaultImplementationContainer.java:180)
    at com.sap.engine.services.webservices.espbase.server.runtime.RuntimeProcessingEnvironment.process0(RuntimeProcessingEnvironment.java:353)
    at com.sap.engine.services.webservices.espbase.server.runtime.RuntimeProcessingEnvironment.preProcess(RuntimeProcessingEnvironment.java:329)
    at com.sap.engine.services.webservices.espbase.server.runtime.RuntimeProcessingEnvironment.process(RuntimeProcessingEnvironment.java:211)
    at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPostWOLogging(ServletDispatcherImpl.java:155)
    at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPostWithLogging(ServletDispatcherImpl.java:96)
    at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPost(ServletDispatcherImpl.java:66)
    at SoapServlet.doPost(SoapServlet.java:51)

[snip]

Caused by: java.lang.NullPointerException
    at org.example.MyPortTypeImplBean.<init>(MyPortTypeImplBean.java:29)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at java.lang.Class.newInstance0(Class.java:350)
    at java.lang.Class.newInstance(Class.java:303)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ApplicationInstancesCreator.invoke(Interceptors_ApplicationInstancesCreator.java:23)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:71)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:189)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_NewBeanContext.invoke(Interceptors_NewBeanContext.java:17)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177)
    at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startCallback(DefaultInvocationChainsManager.java:147)
    at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager.makeExist(StatelessInstanceLifecycleManager.java:108)
    at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager.access$000(StatelessInstanceLifecycleManager.java:23)
    at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager$PoolUserImpl.createObject(StatelessInstanceLifecycleManager.java:34)
    at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.doResizeOneStepUp(ContainerPoolImpl.java:373)
    ... 48 more

Any hints as to figure out what is causing the NullPointer would be greatly appreciated.

Also, what are the guidelines for creating Join Tables or generally managing ManyToMany relationships using JPA and Java Dictionaries? (As the JPA Tools fail to generate the join table, as mentioned above)

Cheers,

Felix

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Active Participant
0 Kudos

Hi Felix,

I have not looked into the stack traces in detail, but with respect to using SAP JPA on Open SQL/DDIC, I would like to point you to our [NetWeaver CE documentation|http://help.sap.com/saphelp_nwce10/helpdata/en/44/eba6292f446c30e10000000a114a6b/frameset.htm]. Here, you'll find a description on how to connect Dali to a Java Dictionary project.

For Open SQL/DDIC working smoothely with Dali 1.0, you have to make sure that you are using the "SAP JPA Platform" and establish a "Connection" to a DDIC project. Once such a connection is established, you can create an offline description of the database tables in the DDIC project and create them on the DB by deployment.

I hope this helps.

-Adrian

Former Member
0 Kudos

Hi Adrian,

I did manage to find this piece of documentation and set my EJB project's settings to what you mention:

Platform: SAP JPA Platform

Connection: dictionary connection

Where dicitonary connection referes to a connection to my Dictionary Project that I created from the Datasource Explorer view. Not sure whether my description in the first post mentions this clearly, but I do succeed on creating all of the tables that are mapped to directly from given entities. However, the join table, that I set up in a JoinTable annotation, is not created. Any clues as to why this happens?

I haven't found much further information on Dictionaries and Dali and am not too familiar with the topics myself. Do you have any further links or hints as to how to debug my project? Thank you for your time!

Cheers,

Felix

Former Member
0 Kudos

After commenting out all the "complicated" mappings, I narrowed it down to the following mapping:

On entity Topic:

@ManyToMany(mappedBy = "topics", fetch = FetchType.EAGER)
private List<SubscriptionIncoming> subscriptionsIncoming;

On entity SubscriptionIncoming:

@ManyToMany(mappedBy = "subscriptionsIncoming", fetch = FetchType.EAGER, targetEntity = Topic.class)
@JoinTable(name = "SII_EVE_J_SI_T",
joinColumns = @JoinColumn(name = "SI_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "T_ID", referencedColumnName = "ID"))
private List<Topic> topics;

The table (SII_EVE_J_SI_T) is the one that I needed to create manually. It consists of the two columns that are mentioned. What is missing for the mapping/relation to work? Let me know if I'm missing some necessary information here. Thank you for your time!

Cheers,

Felix

adrian_goerler
Active Participant
0 Kudos

Hi Felix

please remove

> mappedBy = "subscriptionsIncoming"

on private List<Topic> topics. It confuses JPA. MappedBy must be used on the inverse side of the relationship only. Basically, your relationship has no owning side because you are having a mappedBy on both sides.

Regards

Adrian

Former Member
0 Kudos

Great, that's it Thanks a lot!

Cheers,

felix

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Felix ,

Even I am currently facing the same problem.

Please follow this thread

As per the infro I received , the problem mainly lies in the DataSource creation.

Former Member
0 Kudos

Hi Brian,

not sure where out problems are similar -- could you elaborate on what you mean? Thanks!

Cheers,

Felix

Former Member
0 Kudos

Hi Felix,

Even I got the same error when I used the EntityManagerFactory (null )

and an Injection error when I tried to instantiate Entity Manager

But someone named Yordan Yordanov helped me out , you can find him in my thread , if possible you can ask him him, as he has some knowledge about this.

Brian.

Former Member
0 Kudos

Hi Brian,

I don't think that I have the same problem as you seem to have. At least the connection isn't obvious to me. The datasource seems to work, the problem "should" be related to a problem with my entity relationship mapping.

Cheers,

Felix

ivo_simeonov
Explorer
0 Kudos

Hi Felix,

The new issue seams to be related to your O/R mapping definition. May be the error is reported in the IDE during the build process.

Ivo

Former Member
0 Kudos

If I change the inject to use the setter (and use the application managed entity manager) the error looks like the one I get when using the container managed entity manager:

Caused by: com.sap.engine.lib.injection.InjectionException: Injection on method setEntityManagerFactory of instance org.example.MyPortTypeImplBean@3c2419 failed. Could not get a value to be injected from the factory.
    at com.sap.engine.lib.injection.MethodInjector.inject(MethodInjector.java:115)
    at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22)
    ... 64 more
Caused by: java.lang.NullPointerException
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.getQualifiedName(ORPersistenceModelMappingManager.java:3211)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.processRelations(ORPersistenceModelMappingManager.java:2179)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.processRelations(ORPersistenceModelMappingManager.java:1958)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.getBeanClosure(ORPersistenceModelMappingManager.java:892)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.getBean(ORPersistenceModelMappingManager.java:435)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.LoadModeHandler.getBeanRepresentations(LoadModeHandler.java:258)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.LoadModeHandler.getBeanRepresentations(LoadModeHandler.java:217)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.SQLTreeNodeManager.recognizeRepresentation(SQLTreeNodeManager.java:4101)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.SQLTreeNodeManager.addToSelectList(SQLTreeNodeManager.java:760)
    at com.sap.engine.services.orpersistence.sqlmapper.common.interpret.EJBLoadStoreBuilder.createBeanLoading(EJBLoadStoreBuilder.java:218)
    at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMapper.createEJBSelect(CommonSQLMapper.java:484)
    at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.createQueryDataForFind(SQLMapperHelper.java:84)
    at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.<init>(SQLMapperHelper.java:77)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl$MetaDataImpl.<init>(EntityManagerFactoryImpl.java:141)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:64)
    at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.<init>(JtaEntityManagerFactoryImpl.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createJtaEntityManagerFactory(PersistenceProviderImpl.java:342)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:150)
    at com.sap.engine.services.orpersistence.model.persistenceunit.impl.ExtendedPersistenceUnitInfoImpl.getEntityManagerFactory(ExtendedPersistenceUnitInfoImpl.java:215)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getEMF(ORPersistenceObjectFactory.java:258)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getObjectInstance(ORPersistenceObjectFactory.java:60)
    at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:65)
    at com.sap.engine.lib.injection.MethodInjector.inject(MethodInjector.java:113)
    ... 66 more

Which explains what I did wrong with the application managed approach. However, there are no warnings related to the mapping in the Problems view. Where else would they should up? Thank you for your time!

Cheers,

Felix

Edited by: Felix Geller on May 8, 2008 3:45 PM

ivo_simeonov
Explorer
0 Kudos

Hi Felix,

Sorry but the dependency injection ( DI ) happens after the execution of the constructor. I would suggest to move the emf usage in the business methods or use DI over a setter method instead on a field :

 
    private EntityManager entityManager;
    private EntityManagerFactory emf; 

.............................


    @PersistenceUnit(unitName = "MyEJB")
    public void setEmf(EntityManagerFactory emf) {
          this.emf = emf;
          this.entityManager = emf.createEntityManager();
    }

Former Member
0 Kudos

Perhaps this helps:

If I change the injection from application managed to container manager, as follows

@PersistenceContext(unitName="MyEJB")
private EntityManager entityManager;

The error "changes" to the following: (just the bottom part)

Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field entityManager of instance org.example.MyPortTypeImplBean@145e801 failed. Could not get a value to be injected from the factory.
    at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115)
    at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22)
    ... 64 more
Caused by: java.lang.NullPointerException
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.getQualifiedName(ORPersistenceModelMappingManager.java:3211)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.processRelations(ORPersistenceModelMappingManager.java:2179)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.processRelations(ORPersistenceModelMappingManager.java:1958)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.getBeanClosure(ORPersistenceModelMappingManager.java:892)
    at com.sap.engine.services.orpersistence.sqlmapper.common.model.ORPersistenceModelMappingManager.getBean(ORPersistenceModelMappingManager.java:435)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.LoadModeHandler.getBeanRepresentations(LoadModeHandler.java:258)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.LoadModeHandler.getBeanRepresentations(LoadModeHandler.java:217)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.SQLTreeNodeManager.recognizeRepresentation(SQLTreeNodeManager.java:4101)
    at com.sap.engine.services.orpersistence.sqlmapper.common.assemble.SQLTreeNodeManager.addToSelectList(SQLTreeNodeManager.java:760)
    at com.sap.engine.services.orpersistence.sqlmapper.common.interpret.EJBLoadStoreBuilder.createBeanLoading(EJBLoadStoreBuilder.java:218)
    at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMapper.createEJBSelect(CommonSQLMapper.java:484)
    at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.createQueryDataForFind(SQLMapperHelper.java:84)
    at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.<init>(SQLMapperHelper.java:77)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl$MetaDataImpl.<init>(EntityManagerFactoryImpl.java:141)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:64)
    at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.<init>(JtaEntityManagerFactoryImpl.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createJtaEntityManagerFactory(PersistenceProviderImpl.java:342)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:150)
    at com.sap.engine.services.orpersistence.model.persistenceunit.impl.ExtendedPersistenceUnitInfoImpl.getEntityManagerFactory(ExtendedPersistenceUnitInfoImpl.java:215)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getEMF(ORPersistenceObjectFactory.java:258)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getObjectInstance(ORPersistenceObjectFactory.java:60)
    at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:65)
    at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:113)
    ... 66 more

Cheers,

Felix

Edited by: Felix Geller on May 8, 2008 3:35 PM

ivo_simeonov
Explorer
0 Kudos

Hi Felix,

just look into MyPortTypeImplBean code :

Caused by: java.lang.NullPointerException
    at org.example.MyPortTypeImplBean.(MyPortTypeImplBean.java:29)

There your should find the answer what is null.

Ivo

Former Member
0 Kudos

Hi Ivo,

sorry, I guess I should have mentioned what that line number actually refers to:

@PersistenceUnit(unitName = "MyEJB")
    private EntityManagerFactory emf;
    private EntityManager entityManager = emf.createEntityManager();

Where the last line corresponds to the line in question. I therefore take it, that the dependency injection on the factory fails. However, I'm unsure how to find out what causes the injection to fail.

Cheers,

Felix