When I created my first empty Entreprise Application
with Maven
, I had this error, even when I created an Entity
:
Invalid ejb jar it contains zero ejb
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean.
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.
Entity.java:
package test;
import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@javax.persistence.Entity
public class Entity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
Then I found that the solution to this issue is to add @Stateless
to the `Entity Class:
package test;
import java.io.Serializable;
import javax.ejb.Stateless;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Stateless
@javax.persistence.Entity
public class Entity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
It works fine, but now I want to know why I had to add this annotation to the Entity
to work fine ?
The config details are:
- Netbeans 8.1
- Glassfish 4.1.1
- pgAdmin III
- Maven 3.5
The EAR module has the maven-ear-plugin configured as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>