Skip to main content

IllegalArgumentException trying to inject EntityManager

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2003-07-18

I hava a simple Netbeans/Maven project and I'm using Netbeans 7.3.1 and Glassfish 4.0. I have a stateless session bean about as simple as you can get it:

public class MemberManagerBean implements MemberManager {
    @PersistenceUnit(unitName = "MyPersistenceUnit")
    private EntityManager em;

    public Member insert(Member u) {
        return u;

and I have a persistence.xml again about as simple as you can get it:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <persistence-unit name="MyPersistenceUnit" transaction-type="JTA">
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

I have the Glassfish JDBC pool configured to connect to a PosgreSQL database. No problems connecting to the database from Glassfish.

When the EAR deploys, I know the application is successfully connecting to the PostgreSQL database through the JDBC pool because I see the database tables for my @Entitys get created. So I know the db connection is working.

Problem is when I try to call the EJB I get the following exception:

Caused by: javax.ejb.CreateException: Could not create stateless EJB
        at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(
        at com.sun.ejb.containers.StatelessSessionContainer.access$000(
        at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(
        ... 38 more
Caused by: java.lang.IllegalStateException: Exception attempting to inject Env-Prop: org.ferris.ejb.MemberManagerBean/em@Field-Injectable Resource. Class name = org.ferris.ejb.MemberManagerBean Field name=em@java.lang.String@@@ into class org.ferris.ejb.MemberManagerBean: Can not set javax.persistence.EntityManager field org.ferris.ejb.MemberManagerBean.em to com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper

Any thoughts?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-07-18

1am user error. Need to use @PersistenceContext not @PersistenceUnit