cancel
Showing results for 
Search instead for 
Did you mean: 

Error: Injection on field eManager of instance EmployeeServicesBean failed

NabiZamani
Contributor
0 Kudos

Hi all,

I have access to the customers NW CE 7.1 SP07 and of course I am using the corresponding NWDS 7.1 SP07 that comes with this CE installation. I am trying to study JEE 5 @ SAP and I have created a very simple Application (from the Book http://www.sap-press.de/katalog/buecher/titel/gp/titelID-1480).

In NWDS I have created the following 4 projects:

1. Dictionary Project

Describes 2 Tables (TMP_EMPLOYEES and TMP_ID_GEN)

I could easily deploy it (but on which DataSource are the Tables created? Where do I have to define this??)

2. EJB 5 Project

Contains a stateless EJB + local business interface + Entity class.

The EJB accesses the entity class, which is mapped to a simple table (TMP_EMPLOYEES).

3. Dynamic Web Project

Contains actually only one JSP (index.jsp) which allows to the local business interface for creating a new Entity.

4. Enterprise Application Project (EAR)

Creates a package from 2. and 3. Also includes a self defined data-source-aliases.xml

I have successfully deployed both the Dictionary Project and the EAR (all to the same server).

But If I call the corresponding URL via web browser I get the following error:

Processing HTTP request to servlet [jsp] finished with error. 
The error is: javax.ejb.EJBException: Exception in getMethodReady() for stateless 
bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: 
com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean 
instance com.sap.demo.session.EmployeeServicesBean@298de4eb for bean 
sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; 
nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field eManager of instance com.sap.demo.session.EmployeeServicesBean@298de4eb failed. 
Could not get a value to be injected from the factory.00505684110800290000009000000B180139C8D8862D3E88

I guess I have some buggy "configuration" somewhere. Here is my code:

        1. Stateless EJB: EmployeeServicesBean ###

package com.sap.demo.session;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.sap.demo.entity.Employee;

@Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER)
public class EmployeeServicesBean implements EmployeeServicesLocal {


        //ATTENTION: it seems the error occurs here, because "eManager" can't be filled :-(
	@PersistenceContext(unitName="EmployeePU_NZA")
	private EntityManager eManager;
	
	public long createEmployee(String lastName, String firstName, String department){
		
		long result = 0;
		Employee emp = new Employee();
		emp.setFirstName(firstName);
		emp.setLastName(lastName);
		emp.setDepartment(department);
		
		eManager.persist(emp);
		result = emp.getEmployeeId();
		
		return result;
	}
	
	@TransactionAttribute(TransactionAttributeType.SUPPORTS)
	public Employee getEmployeeById(long id){
		Employee emp = eManager.find(Employee.class, id);
		return emp;
	}
	
	@SuppressWarnings("unchecked")
	@TransactionAttribute(TransactionAttributeType.SUPPORTS)
	public List<Employee> getAllEmployees(){
		
		Query query = eManager.createNamedQuery("Employee.findAll");
		List<Employee> res = (List<Employee>)query.getResultList();
		
		return res;
	}
	
}

        1. persistence.xml ###

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns:persistence="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd ">
	<persistence-unit name="EmployeePU_NZA">
		<jta-data-source>TMP_NZA_EMPLOYEES_DATA</jta-data-source>
		<properties>
			<property name="com.sap.engine.services.orpersistence.generator.versiontablename" value="TMP_ID_GEN" />			
		</properties>
	</persistence-unit>
</persistence>

        1. data-source-aliases.xml ###

<?xml version="1.0" encoding="UTF-8"?>

<data-source-aliases xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="data-source-aliases.xsd">

<aliases>

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

<alias>TMP_NZA_EMPLOYEES_DATA</alias>

</aliases>

</data-source-aliases>

        1. Entity class: Employee ###

package com.sap.demo.entity;

import java.io.Serializable;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.NamedQuery;

import javax.persistence.Table;

import javax.persistence.TableGenerator;

import javax.persistence.Version;

@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee AS e")

@Entity

@Table(name="TMP_EMPLOYEES")

@TableGenerator(name="idGenerator", table="TMP_ID_GEN", pkColumnName="GEN_KEY", valueColumnName="GEN_VALUE")

public class Employee implements Serializable{

private static final long serialVersionUID = 111l;

@Id

@GeneratedValue(strategy=GenerationType.TABLE, generator="idGenerator")

@Column(name="ID")

private long employeeId;

@Column(name="LAST_NAME")

private String lastName;

@Column(name="FIRST_NAME")

private String firstName;

private String department;

@Version

private int version;

public Employee(){

}

//getters and setters...

[...]

}

      1. data-source-aliases.xml of Enterprise Application Project ###


<?xml version="1.0" encoding="UTF-8"?>
<data-source-aliases xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="data-source-aliases.xsd">
  <aliases>
    <data-source-name>${com.sap.datasource.default}</data-source-name>
    <alias>TMP_NZA_EMPLOYEES_DATA</alias>
  </aliases>
</data-source-aliases>

Who can see my problem? I have been trying for the last 3 days to find the problem

Thanks!!!

Accepted Solutions (0)

Answers (6)

Answers (6)

NabiZamani
Contributor
0 Kudos

HI Vesselin,

sorry, it doean't help. I have tried all that plenty of times!

Regards,

Pars

0 Kudos

Hi again,

I think the only possibility then is inconsistency between the state of table TMP_ID_GEN on the database, and the table metadata kept by Open SQL on the application server.

You should never edit the tables directly on the database, but deploy them using the engine deployment mechanism.

Best regards,

Vesselin

NabiZamani
Contributor
0 Kudos

As I described I have changed the line

@TableGenerator(name="idGenerator", table="TMP_ID_GEN", pkColumnName="GEN_KEY", valueColumnName="GEN_VALUE")

to

@TableGenerator(name="idGenerator", table="TMP_ID_GEN", pkColumnName="GEN_KEY", valueColumnName="GEN_VAL")

and redeployed plenty of times the CE 7.1 I do use did not get it right. I have no idea why, but it keeps throwing this error:

The SQL statement "SELECT "GEN_VALUE" FROM "TMP_ID_GEN" WHERE "GEN_KEY" = ? FOR UPDATE"

contains the semantics error[s]: - 1:8 - the column >>GEN_VALUE<< is undefined in the current scope .

That really is a mytery to me. The only solution I had is to create all my 4 projects again from scratch, and thime everything correctly from the beginning. And guess what: this time it really worked. I know that this is not a good approach and I really hope that I am simply to stupid to find the right way...

Thanks anyway...

Pars

0 Kudos

Hi Parsman,

You are sure that this is the last exception you are getting? If so, make sure you don't have any other entities defining generators with GEN_VALUE instead of GEN_VAL.

Also make sure you have re-deployed successfully the application on the server so that the version of your entity is really the new one.

Hope this helps.

Best regards,

Vesselin

NabiZamani
Contributor
0 Kudos

But now I have other issue, or maybe even the same:

In the log Viewer of my nwa I see the 4 errors occuring in the following chronological order:

1.


Exception of type com.sap.sql.log.OpenSQLException caught: 
The SQL statement "SELECT "GEN_VALUE" FROM "TMP_ID_GEN" WHERE "GEN_KEY" = ? FOR UPDATE" contains the semantics error[s]: - 1:8 - the column >>GEN_VALUE<< is undefined in the current scope

2.


System exception  
[EXCEPTION]
 javax.ejb.EJBException: Exception in getMethodReady() for stateless bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 for bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field eManager of instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 failed. Could not get a value to be injected from the factory. 
com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 for bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field eManager of instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 failed. Could not get a value to be injected from the factory. 
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.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:164) 
at $Proxy1675.createEmployee(Unknown Source) 
at JEE_jsp_index_8832250_1231951553946_1231951588930._jspService(JEE_jsp_index_8832250_1231951553946_1231951588930.java:123) 
at com.sap.engine.services.servlets_jsp.lib.jspruntime.JspBase.service(JspBase.java:102)


//and many more

3.


Processing HTTP request to servlet [jsp] finished with error. The error is: javax.ejb.EJBException: Exception in getMethodReady() for stateless bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 for bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field eManager of instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 failed. Could not get a value to be injected from the factory. 
com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 for bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field eManager of instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 failed. Could not get a value to be injected from the factory. 
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) 

//and many more

4.


Processing HTTP request to servlet [jsp] finished with error. 
The error is: javax.ejb.EJBException: Exception in getMethodReady() for stateless bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 for bean sap.com/EmployeeEar*annotation|EmployeeEjb.jar*annotation|EmployeeServicesBean; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field eManager of instance com.sap.demo.session.EmployeeServicesBean@25f56eb4 failed. Could not get a value to be injected from the factory.0050568411080026000000B500000B180139C8D8862D3408

Who understands these error logs?

Why it says

"SELECT "GEN_VALUE" FROM "TMP_ID_GEN" WHERE "GEN_KEY" = ? FOR UPDATE" contains the semantics error

although I have corrected this already (see previous post) and deployed plenty of times???

I mus have some other stupid bug somewhere, but I can't find it. That really drives me crazy...

NabiZamani
Contributor
0 Kudos

Dear all,

First issue found. As you can see above in the entity class Employee I have added the following annotation:

@TableGenerator(name="idGenerator", table="TMP_ID_GEN", pkColumnName="GEN_KEY", valueColumnName="GEN_VALUE")

Unfortunately the table "TMP_ID_GEN" does not contain a field called "GEN_VALUE". Instead it has a field called "GEN_VAL". That means I have changed the code as follows:

@TableGenerator(name="idGenerator", table="TMP_ID_GEN", pkColumnName="GEN_KEY", valueColumnName="GEN_VAL")

NabiZamani
Contributor
0 Kudos

Please use this link:

[|]

Please consider that this issue is seems to be almost the same and is still not solved!

NabiZamani
Contributor
0 Kudos

Hi again,

it seems this is a common issue for beginners.

See here:

[SDN post from Aug 27, 2008|http://209.85.129.132/search?q=cache:HgktljUWKXoJ:https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.sdn.folder.sdn!2fcom.sap.sdn.folder.application!2fcom.sap.sdn.folder.roles!2fcom.sap.sdn.folder.navigationroles!2fcom.sap.sdn.role.anonymous!2fcom.sap.sdn.tln.workset.forums!2fforumtest!2fcom.sap.sdn.app.iview.forumthread%3FQuickLink%3Dthread%26tstart%3D0%26messageID%3D5961459sapce7.1InjectiononfieldEntityManagerofinstance%2Bfailed&hl=de&ct=clnk&cd=17&gl=de]

I am still struggeling with this issue