IDE : NetBeans 8.1
AP Server: GlassFish 4.1
Framework: JSF2.2 + Omnifaces 2.2
When I right-click on the Project > Run as Pic 1
the applicationBean with @Eager annotation(Omnifaces) was started before the web application deployed(from server.log), and it makes some exception or bug:
- This web container has not yet been started
- Object: model.entity.NePingMin[ id=null ] is not a known entity type.
BUT at Services > Server > right-click on GlassFish > Start as Pic 2
It works without any exception...... lol
It is caused by Omnifaces bugs?
Application Bean:
import org.omnifaces.cdi.Eager;
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
@Named
@ApplicationScoped
@Eager
public class pingController {
PingThread pingThread;
@PostConstruct
public void init() {
t = new PingThread();
t.start();
....
Other Code:
public class PingThread extends Thread {
@Override
public void run() {
while (true) {
try {
Thread.sleep(30000);
spmsEm = JPAUnit.getSPMSEntityManagerFactory().createEntityManager(); //RESOURCE_LOCAL
//PingResult is just a simple POJO
//but it will throw java.lang.IllegalStateException:
// This web container has not yet been started
PingResult result = new PingResult()
....
try {
EntityTransaction eT = spmsEm.getTransaction();
if (!eT.isActive()) {
eT.begin();
}
//An entity class
//It will throw java.lang.IllegalArgumentException:
// Object: model.entity.NePingMin[ id=null ] is not a known entity type.
NePingMin np = new NePingMin();
np.setCount(p.count);
np.setNeId(c.getControllerId());
np.setNeType("controller");
np.setSuccessCount(p.successCount);
np.setRecordTime(new Date(System.currentTimeMillis()));
spmsEm.persist(np);
eT.commit();
} catch (Exception ex) {
ex.printStackTrace();
}
.....