cancel
Showing results for 
Search instead for 
Did you mean: 

Entity Manager Problem

Former Member
0 Kudos

Now that I can look up an object with JNDI I try to save some data with the following entity bean:


@Entity
public class Supplier implements Serializable {
	@Id
	@Column(name="SUPPLIER_ID")
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int supplierId;

	@Column(name="SUPPLIER_STREET")
	private String supplierStreet;

	@Column(name="SUPPLIER_NAME")
	private String supplierName;

	@Column(name="SUPPLIER_CITY")
	private String supplierCity;

	@Column(name="SUPPLIER_ZIPCODE")
	private int supplierZipcode;
... Getter and Setters ...

I have also written a stateless session bean that looks like this:


@Stateless
public class SupplierAgentBean implements SupplierAgentRemote, SupplierAgentLocal {
	@PersistenceContext(unitName="SUPPLIER_PU", type=PersistenceContextType.TRANSACTION)
	private EntityManager em;
	
	public void createSupplier(Supplier supplier) {
		em.persist(supplier);
	}
	
	public Supplier findSupplier(int supplierId) {
		return em.find(Supplier.class, supplierId);
	}
}

When I try to call the createSupplier method with its remote interface (supplierAgentRemote.createSupplier(supplier);) I get the following error message:


Exception in thread "main" javax.ejb.EJBException: Exception in getMethodReady() for stateless bean sap.com/SAP_SupplierEAR*annotation|SAP_SupplierEJB.jar*annotation|SupplierAgentBean; nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sipro.supplier.sessions.SupplierAgentBean@14298ae for bean sap.com/SAP_SupplierEAR*annotation|SAP_SupplierEJB.jar*annotation|SupplierAgentBean; nested exception is: com.sap.engine.services.ejb3.injection.InjectionException: Injection on field em of instance com.sipro.supplier.sessions.SupplierAgentBean@14298ae failed. Could not get a value to be injected from the factory.

Can anyone help me out?

Arne

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Active Participant
0 Kudos

Hi Arne,

please have a look in the default trace of the Java EE engine to find out why the (entity manager) factory cannot be injected. You find the default trace under

C:\SAP\JP1\JC02\j2ee\cluster\server0\log\defaultTrace.0.trc.

A frequent reason for the failing injection of the entity manager factory are missing or not-matching database tables. Please double-check that all tables required by your entities are present.

Also, please not that GenerationType.AUTO requires the existence of a database table "TMP_SEQUENCE" with two columns:

GEN_KEY (VARCHAR(128), primary key)

GEN_VALUE (BIGINT or INTEGER).

This table is not created automatically.

Finally, please make sure that the persistence unit name specified in the persistence.xml matches the persistence unit name used in the entity manager injection ("SUPPLIER_PU").

I hope this helps,

Adrian

Answers (1)

Answers (1)

Former Member
0 Kudos

Creating table TMP_SEQUENCE solved the problem. Thanks!