cancel
Showing results for 
Search instead for 
Did you mean: 

JPA - Injection on field em of instance com.xxx.classname@6ace05c2 failed

Former Member
0 Kudos

Hi everyone

I'm having a problem with JPA, and can't think of what's going wrong here. Please could someone help point out what may be going wrong here?

This is my persistence.xml file:


<persistence>
<persistence-unit name="ARM">
<jta-data-source>ARM_DS</jta-data-source>
</persistence-unit>
</persistence>

Then in my EJB, I have the following:


@PersistenceContext(unitName="ARM")
private EntityManager em;

Then I've defined the data source alias in the data-source-aliases.xml file (in the EAR project):


<data-source-aliases>
<aliases>
<data-source-name>${com.sap.datasource.default}</data-source-name>
<alias>ARM_DS</alias>
</aliases>
</data-source-aliases>

Please could someone point out where I may be going wrong here. I've read through a lot of the JPA documentation and it appears that it's all correct - but I'm completely new to this, so could be missing something obvious.

Thanks

Stuart

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Stuart,

since your error message is not detailed enough for a proper analysis of your problem I kindly ask you to share your defaultTrace log-file from your filesystem. I should find it under a location like this:

%DRIVE%:\usr\sap\%SID%\%INSTANCE_NUMBER%\j2ee\cluster\server0\log

Please reproduce the steps that lead to the error and then take the last part of the latest defaultTrace_XX.XX.trc file. There should be more information about the root-cause than in the error message you posted before.

Best Regards,

Robin

Former Member
0 Kudos

Hi Robin

That helped immensely! I've never really known which logs to check for errors beacuse there are so many, but that log had the exact errors to help me.

The problem seems to be with a @NamedQuery that I've defined on one of my entities.


SELECT e FROM TMP_EMPLOYEE e WHERE e.firstname = :firstname
              ^

The exception text is: line 1: Abstract Schema Type 'TMP_EMPLOYEE' doesn't exist

Any suggestions on what to use as a schema? I can't use the default schema, as that varies from one system to another (ie. SAP<SID>DB).

Any thoughts?

Thanks again for all the help guys!

Former Member
0 Kudos

Hi Stuart,

this is a very obvious error.. Since JPQL (which you use here as the query language) is working on the object- or entity level you must not use the name of your database schema or table in the select statement. Please use the entity name.Your query should then look like this:

SELECT e FROM Employee e WHERE e.firstname = :firstname

Best Regards,

Robin

Former Member
0 Kudos

Hmmm... amateur mistake

Thanks very much! Now I can continue making other stupid mistakes elsewhere

Former Member
0 Kudos

Yeah, but somehow it's really time-consuming (for beginnners) to wait until deployment to see the errors in their JPQL queries. We already identified this as an issue and are working on a solution. Look out for future releases of NetWeaver CE.

Best Regards,

Robin

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Stuart,

Dont worry , even I went through the same phase...

So lets keep the approach simple.

Create an EJB module, within that an EJB EJBsource(stateless Session Bean). One EAR module EARsource.

Now suppose that our client is a Composite Application(as in my case,with a Stateless Session Bean EJBclient and an EAR module EARclient).

To add the dependencies:

1) To add the design time dependency --> simply add the EJBsource as a dependency for the EJBclient.........So now u would see the Entities in your client for coding.

Now for run time dependency

Done in Development Infrastructure Perspective

2)In the EJBsource and in the permissions tab, select MyComponents for Entity Forwarding.

3)In the EARsource add a new Public Part, and Reference entities --> client of the EJBsource

4)Finally now add this EARsource as a dependency to the EARclient.

Thats it ............Reward points if useful

If you face any more difficulty, you can ask me.

HTH ..

cheers

---Brian.

Former Member
0 Kudos

Thanks Brian

Unfortunately it seems we're having different problems (although I'm getting the same error as you got). I don't think mine is dependency-related, but hopefully I get to the bottom of it soon!

Thanks for your help.

Cheers

Stuart

Former Member
0 Kudos

Hi, Stuart,

I cannot guarantee, that these would help, but:

1. Try declaring your EntityManager as public, not private.

2. If your data-source-aliases.xml is not part of your application EAR (i.e. if you are deploying your DS alias separate from your application), you must add the <application-name>YOUR_APPLICATION_NAME</application-name> before the <aliases> element. (More information: http://help.sap.com/saphelp_nwce10/helpdata/en/45/c82cd460a42e96e10000000a155369/frameset.htm)

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan

Thanks for your response. I tried both of your suggestions, but unfortunately it still gives the same error.

The data-source-aliases.xml file is deployed as part of the EAR, but I included the application name as you suggested.

Is there anything else you can think of that I may be doing wrong?

Thanks

Stuart

Former Member
0 Kudos

I noticed something else, which may or may not be the cause of the problem. Perhaps you could help shed some light on this.

I have 4 projects:

- Dictionary

- EJB

- Web

- EAR

When adding the JPA facet to my EJB project, I selected SAP JPA Platform, and created a connection using my Dictionary Project (connection profile: DDIC Designtime). When I look at my connection in the Data Source Explorer, it shows all data under the <ProjectName> schema.

I remember reading here [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40ff8a3d-065a-2910-2f84-a222e03d1f43] (see note at the top of page 6) that we must use the SAPDEMO schema for our applications.

Please could you clarify if this is correct? And if so, how do I get my Dictionary project to create the tables in the correct schema?

As I said, this may not be related, but's something I'm unsure of - so hopefully this helps resolve the problem.

Thanks

Stuart

Former Member
0 Kudos

Hi, Stuart,

>

> When adding the JPA facet to my EJB project, I selected SAP JPA Platform, and created a connection using my Dictionary Project (connection profile: DDIC Designtime). When I look at my connection in the Data Source Explorer, it shows all data under the <ProjectName> schema.

That's exactly how it should be. So, don't worry.

SAPDEMO is used in the particular tutorial that you referenced.

I still do not have an idea what might be your problem as everything you posted/quoted seems fine to me.

Just FYI: If you want, you can simplify your work by doing forward mapping (create entities >> generate Dictionary tables) or backward mapping (create Dictionary tables >> generate entities).

More information:

http://help.sap.com/saphelp_nwce10/helpdata/en/46/8b38425f9c6be3e10000000a155369/frameset.htm

http://help.sap.com/saphelp_nwce10/helpdata/en/44/edbd4aa338108ee10000000a11466f/frameset.htm

Regards,

Yordan

ADDED: What came to my mind is, did you organize your imports (especially, those of your java bean)?

(If you are using NWDS) Right-click in the bean source code >> "Source" >> "Organize Imports"

If this is OK, then I guess the problem might be in your Entity Manager instantiation and method calls...

Former Member
0 Kudos

Hi Yordan

I've organised all imports, and that's all fine - and building ok.

What do you mean by EntityManager instantiation? I thought that was injected by the EJB container, and I didn't need to instantiate it myself? I'm getting the injection error even when calling a method that doesn't use the EntityManager at all.

This is the error I get when calling a method that doesn't use the EntityManager. It seems the exception is thrown before my method is even called.

Exception in getMethodReady() for stateless bean sap.com/ArtistPortalEARannotation|ArtistPortalEJB.jarannotation|SecurityServiceBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.g3global.arm.services.SecurityServiceBean@84cead8 for bean sap.com/ArtistPortalEARannotation|ArtistPortalEJB.jarannotation|SecurityServiceBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.g3global.arm.services.SecurityServiceBean@84cead8 failed. Could not get a value to be injected from the factory.