I'm working on a webapp using wildfly and hibernate.
Below is some of my code and config files.
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">removed</property>
<property name="hibernate.connection.url">jdbc:postgresql:reportbuilderwebservices</property>
<property name="hibernate.connection.username">removed</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping class="org.declercq.reportbuilderback.models.User"/>
<mapping class="org.declercq.reportbuilderback.models.Permission"/>
<mapping class="org.declercq.reportbuilderback.models.Role"/>
<mapping class="org.declercq.reportbuilderback.models.Vulnerability"/>
<mapping class="org.declercq.reportbuilderback.models.Finding"/>
</session-factory>
</hibernate-configuration>
My model class User.java with annotations:
package org.declercq.reportbuilderback.models;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "users")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id #GeneratedValue
#Column(name="id")
private int id;
#Column(name="username")
private String userName;
#Column(name="password")
private String password;
#Column(name="email")
private String emailAddress;
public User(String userName, String password, String emailAddress) {
super();
this.userName = userName;
this.password = password;
this.emailAddress = emailAddress;
}
public User() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
}
My DAO method:
public List<User> getAllUsers(){
System.out.println("0");
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
System.out.println("0,5");
Transaction tx = null;
List<User>allUsers=null;
try{
tx = session.beginTransaction();
System.out.println("1");
allUsers = session.createQuery("from User u").getResultList();
System.out.println("2");
tx.commit();
System.out.println("3");
}
catch(HibernateException e){
if(tx != null){
tx.rollback();
System.out.println("4");
}
return allUsers;
}
finally{
session.close();
System.out.println("5");
return allUsers;
}
}
My hibernate.util:
package org.declercq.reportbuilderback.dao;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
Configuration configuration = new Configuration().configure();
configuration.configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(ssrb.build());
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
My webservice:
package org.declercq.reportbuilderback.webservices;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.declercq.reportbuilderback.dao.UserDao;
import org.declercq.reportbuilderback.models.User;
#Path("/userwebservice")
public class UserWebService {
#Path("/users")
#GET
#Produces("application/json")
public List<User> listUsers(){
System.out.println("HERE");
List<User>allUsers=new UserDao().getAllUsers();
System.out.println("Now here");
System.out.println("Size: "+allUsers.size());
return allUsers;
}
}
My pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>reportbuilderback</groupId>
<artifactId>org.declercq.reportbuilderback</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>async-http-servlet-3.0</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.0.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.3.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-all</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
My server output:
The strange thing is, if you look at my output in console (where I use the system.out.println), the DAO code jumps from creating a transaction straight to closing the session, it doesn't even build my query.
The result is of course that my database query result is null, hence the nullpointerexception. This I understand, but I have no idea why the DAO code isn't executing correctly...
I'm thinking it's because of my pom configuration, something library at compile versus library from wildfly, but I have no idea...
UPDATE 1:
After changing my code as described below:
#SuppressWarnings({ "unchecked", "deprecation" })
public List<User> getAllUsers(){
System.out.println("0");
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
System.out.println("0,5");
Transaction tx = null;
List<User>allUsers=null;
try{
tx = session.beginTransaction();
System.out.println("1");
//allUsers = session.createQuery("select u from User u").getResultList();
allUsers=session.createCriteria(User.class).list();
System.out.println("2");
tx.commit();
System.out.println("3");
}
catch(HibernateException e){
if(tx != null){
tx.rollback();
System.out.println("4");
}
return allUsers;
}
finally{
session.close();
System.out.println("5");
return allUsers;
}
}
I now get following output:
08:32:37,957 INFO [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final
08:32:38,350 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
08:32:38,467 INFO [org.jboss.as] (MSC service thread 1-8) WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting
08:32:41,471 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war in deployment directory. To trigger deployment create a file called org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war.dodeploy
08:32:41,641 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
08:32:41,715 INFO [org.xnio] (MSC service thread 1-6) XNIO version 3.4.0.Final
08:32:41,728 INFO [org.xnio.nio] (MSC service thread 1-6) XNIO NIO Implementation Version 3.4.0.Final
08:32:41,856 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 4.0.21.Final
08:32:41,958 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
08:32:41,990 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
08:32:42,007 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
08:32:42,059 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
08:32:42,097 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
08:32:42,123 INFO [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
08:32:42,126 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
08:32:42,175 INFO [org.jboss.as.connector] (MSC service thread 1-4) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.4.Final)
08:32:42,208 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0003: Undertow 1.4.0.Final starting
08:32:42,213 INFO [org.jboss.as.security] (MSC service thread 1-6) WFLYSEC0001: Current PicketBox version=4.9.6.Final
08:32:42,473 INFO [org.jboss.as.naming] (MSC service thread 1-6) WFLYNAM0003: Starting Naming Service
08:32:42,477 INFO [org.jboss.as.mail.extension] (MSC service thread 1-7) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
08:32:42,523 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
08:32:42,535 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0018: Started Driver service with driver-name = h2
08:32:42,853 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path '/home/wouter/wildfly-10.1.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
08:32:42,889 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0012: Started server default-server.
08:32:42,897 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0018: Host default-host starting
08:32:43,108 INFO [org.jboss.as.ejb3] (MSC service thread 1-7) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
08:32:43,109 INFO [org.jboss.as.ejb3] (MSC service thread 1-4) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
08:32:43,251 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
08:32:43,729 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
08:32:44,048 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-5) WFLYDM0111: Keystore /home/wouter/wildfly-10.1.0.Final/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
08:32:44,093 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-8) WFLYDS0013: Started FileSystemDeploymentService for directory /home/wouter/wildfly-10.1.0.Final/standalone/deployments
08:32:44,112 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war" (runtime-name: "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war")
08:32:44,508 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-4) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.4.Final
08:32:44,547 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
08:32:44,617 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
08:32:44,614 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 60) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
08:32:44,621 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 60) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
08:32:44,616 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
08:32:44,623 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
08:32:44,633 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
08:32:44,841 INFO [org.jboss.ws.common.management] (MSC service thread 1-5) JBWS022052: Starting JBossWS 5.1.5.Final (Apache CXF 3.1.6)
08:32:47,678 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war
08:32:47,783 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-5) HV000001: Hibernate Validator 5.2.4.Final
08:32:48,163 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.4)
08:32:48,236 INFO [org.jboss.weld.Version] (MSC service thread 1-1) WELD-000900: 2.3.5 (Final)
08:32:48,315 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war_org.postgresql.Driver_9_4
08:32:51,378 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 64) RESTEASY002225: Deploying javax.ws.rs.core.Application: class org.declercq.reportbuilderback.webservices.ConfigApp
08:32:51,429 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 64) WFLYUT0021: Registered web context: /org.declercq.reportbuilderback-0.0.1-SNAPSHOT
08:32:51,498 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war" (runtime-name : "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war")
08:32:51,731 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
08:32:51,731 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
08:32:51,732 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 14785ms - Started 476 of 724 services (404 services are lazy, passive or on-demand)
08:32:57,477 INFO [stdout] (default task-3) HERE
08:32:57,480 INFO [stdout] (default task-3) 0
08:32:57,639 INFO [org.hibernate.Version] (default task-3) HHH000412: Hibernate Core {5.2.3.Final}
08:32:57,641 INFO [org.hibernate.cfg.Environment] (default task-3) HHH000206: hibernate.properties not found
08:32:57,644 INFO [org.hibernate.cfg.Environment] (default task-3) HHH000021: Bytecode provider name : javassist
08:32:58,527 INFO [org.hibernate.annotations.common.Version] (default task-3) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
08:32:58,725 WARN [org.hibernate.orm.connections.pooling] (default task-3) HHH10001002: Using Hibernate built-in connection pool (not for production use!)
08:32:58,727 INFO [org.hibernate.orm.connections.pooling] (default task-3) HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql:reportbuilderwebservices]
08:32:58,729 INFO [org.hibernate.orm.connections.pooling] (default task-3) HHH10001001: Connection properties: {user=reportbuilderwebservices, password=****}
08:32:58,730 INFO [org.hibernate.orm.connections.pooling] (default task-3) HHH10001003: Autocommit mode: false
08:32:58,734 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (default task-3) HHH000115: Hibernate connection pool size: 10 (min=1)
08:32:58,844 INFO [org.hibernate.dialect.Dialect] (default task-3) HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
08:32:59,106 INFO [org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl] (default task-3) HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
08:32:59,109 INFO [org.hibernate.type.BasicTypeRegistry] (default task-3) HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#48ea9b0e
08:32:59,449 INFO [org.hibernate.tool.schema.internal.SchemaCreatorImpl] (default task-3) HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#43b645ed'
08:32:59,632 INFO [stdout] (default task-3) 0,5
08:32:59,636 INFO [stdout] (default task-3) 1
08:32:59,640 WARN [org.hibernate.orm.deprecation] (default task-3) HHH90000022: Hibernate's legacy org.hibernate.Criteria API is deprecated; use the JPA javax.persistence.criteria.CriteriaQuery instead
08:32:59,653 INFO [stdout] (default task-3) 2
08:32:59,657 INFO [stdout] (default task-3) 3
08:32:59,658 INFO [stdout] (default task-3) 5
08:32:59,659 INFO [stdout] (default task-3) Now here
08:32:59,660 INFO [stdout] (default task-3) Size: 0
So, 2 issues here: 1) for some reason, this executes while the previous method of createQuery did not. I really want to know why, since this way (using criteria) apparently is deprecated. 2) Most important reason of all: I print out the size of allUsers at the end, the size is 0, which is absolutely not possible, since there are 3 user accounts added in that users table.
Can someone assist please?
Thanks!
createQuery is returning null, which usually means that there is something wrong with the query string. You could try, for example:
allUsers = session.createQuery("from User").getResultList();
Or JPA compliant way:
allUsers = session.createQuery("select u from User u").getResultList();
Or without hql:
allUsers = session.createCriteria(User.class).list();
Related
I'm building a webapp using hibernate and wildfly.
Below the content of some of my files:
Hibernate model user.java:
package org.declercq.reportbuilderback.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity (name="User")
#Table(name = "users")
public class User {
#Id #GeneratedValue
#Column(name="id")
private int id;
#Column(name="username")
private String userName;
#Column(name="password")
private String password;
#Column(name="email")
private String emailAddress;
public User(String userName, String password, String emailAddress) {
super();
this.userName = userName;
this.password = password;
this.emailAddress = emailAddress;
}
public User() {
super();
}
public int getId() {
return id;
}
}
My hibernate util class:
package org.declercq.reportbuilderback.dao;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
//import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
if(sessionFactory == null){
// loads configuration and mappings
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
// builds a session factory from the service registry
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}
}
My DAO method used:
public List<User> getAllUsers(){
System.out.println("0");
Session session=HibernateUtil.getSessionFactory().openSession();
System.out.println("0,5");
Transaction tx = null;
List<User> allUsers=null;
try{
tx = session.beginTransaction();
System.out.println("1");
allUsers = session.createQuery("FROM org.declercq.reportbuilderback.models.User").getResultList();
System.out.println("2");
tx.commit();
System.out.println("3");
return allUsers;
}
catch(HibernateException e){
if(tx != null){
tx.rollback();
System.out.println("4");
}
return allUsers;
}
finally{
session.close();
System.out.println("5");
}
}
This method is called by a web service:
package org.declercq.reportbuilderback.webservices;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.declercq.reportbuilderback.dao.UserDao;
import org.declercq.reportbuilderback.models.User;
#Path("/userwebservice")
public class UserWebService {
#Path("/users")
#GET
#Produces("application/json")
public List<User> listUsers(){
System.out.println("HERE");
List<User>allUsers=new UserDao().getAllUsers();
System.out.println("Now here");
System.out.println("Size: "+allUsers.size());
return allUsers;
}
}
My hibernate config file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">removed</property>
<property name="hibernate.connection.url">jdbc:postgresql://127.0.0.1:5432/reportbuilderwebservices</property>
<property name="hibernate.connection.username">removed</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.connection.pool_size">20</property>
<mapping class="org.declercq.reportbuilderback.models.User"/>
<mapping class="org.declercq.reportbuilderback.models.Permission"/>
<mapping class="org.declercq.reportbuilderback.models.Role"/>
<mapping class="org.declercq.reportbuilderback.models.Vulnerability"/>
<mapping class="org.declercq.reportbuilderback.models.Finding"/>
</session-factory>
</hibernate-configuration>
When I'm deploying this to wildfly, I'm getting the following in console:
16:47:17,758 INFO [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final
16:47:18,100 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
16:47:18,239 INFO [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting
16:47:20,325 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war in deployment directory. To trigger deployment create a file called org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war.dodeploy
16:47:20,488 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
16:47:20,532 INFO [org.xnio] (MSC service thread 1-6) XNIO version 3.4.0.Final
16:47:20,568 INFO [org.xnio.nio] (MSC service thread 1-6) XNIO NIO Implementation Version 3.4.0.Final
16:47:20,657 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 4.0.21.Final
16:47:20,748 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
16:47:20,782 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
16:47:20,881 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
16:47:20,896 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
16:47:20,897 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
16:47:20,916 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
16:47:20,929 INFO [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
16:47:20,940 INFO [org.jboss.as.connector] (MSC service thread 1-6) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.4.Final)
16:47:20,945 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0018: Started Driver service with driver-name = h2
16:47:20,963 INFO [org.jboss.as.security] (MSC service thread 1-3) WFLYSEC0001: Current PicketBox version=4.9.6.Final
16:47:21,244 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
16:47:21,318 INFO [org.jboss.as.naming] (MSC service thread 1-2) WFLYNAM0003: Starting Naming Service
16:47:21,334 INFO [org.jboss.as.mail.extension] (MSC service thread 1-2) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
16:47:21,381 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0003: Undertow 1.4.0.Final starting
16:47:21,904 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path '/home/wouter/wildfly-10.1.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
16:47:22,028 INFO [org.jboss.as.ejb3] (MSC service thread 1-8) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
16:47:22,029 INFO [org.jboss.as.ejb3] (MSC service thread 1-6) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
16:47:22,040 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0012: Started server default-server.
16:47:22,042 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0018: Host default-host starting
16:47:22,225 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
16:47:22,744 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
16:47:23,033 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-4) WFLYDM0111: Keystore /home/wouter/wildfly-10.1.0.Final/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
16:47:23,066 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-8) WFLYDS0013: Started FileSystemDeploymentService for directory /home/wouter/wildfly-10.1.0.Final/standalone/deployments
16:47:23,085 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war" (runtime-name: "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war")
16:47:23,635 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.4.Final
16:47:23,683 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
16:47:23,697 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
16:47:23,722 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
16:47:23,728 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 58) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
16:47:23,704 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
16:47:23,734 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
16:47:23,731 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 58) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
16:47:24,060 INFO [org.jboss.ws.common.management] (MSC service thread 1-5) JBWS022052: Starting JBossWS 5.1.5.Final (Apache CXF 3.1.6)
16:47:26,386 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war
16:47:26,897 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-7) HV000001: Hibernate Validator 5.2.4.Final
16:47:27,312 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.4)
16:47:27,364 INFO [org.jboss.weld.Version] (MSC service thread 1-5) WELD-000900: 2.3.5 (Final)
16:47:27,465 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war_org.postgresql.Driver_9_4
16:47:30,321 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 65) RESTEASY002225: Deploying javax.ws.rs.core.Application: class org.declercq.reportbuilderback.webservices.ConfigApp
16:47:30,383 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 65) WFLYUT0021: Registered web context: /org.declercq.reportbuilderback-0.0.1-SNAPSHOT
16:47:30,419 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war" (runtime-name : "org.declercq.reportbuilderback-0.0.1-SNAPSHOT.war")
16:47:30,634 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
16:47:30,635 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
16:47:30,637 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 13428ms - Started 476 of 724 services (404 services are lazy, passive or on-demand)
16:51:38,771 INFO [stdout] (default task-3) HERE
16:51:38,774 INFO [stdout] (default task-3) 0
16:51:38,891 INFO [org.hibernate.Version] (default task-3) HHH000412: Hibernate Core {5.2.3.Final}
16:51:38,895 INFO [org.hibernate.cfg.Environment] (default task-3) HHH000206: hibernate.properties not found
16:51:38,898 INFO [org.hibernate.cfg.Environment] (default task-3) HHH000021: Bytecode provider name : javassist
16:51:39,501 INFO [org.hibernate.annotations.common.Version] (default task-3) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
16:51:39,688 WARN [org.hibernate.orm.connections.pooling] (default task-3) HHH10001002: Using Hibernate built-in connection pool (not for production use!)
16:51:39,690 INFO [org.hibernate.orm.connections.pooling] (default task-3) HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://127.0.0.1:5432/reportbuilderwebservices]
16:51:39,691 INFO [org.hibernate.orm.connections.pooling] (default task-3) HHH10001001: Connection properties: {user=reportbuilderwebservices, password=****}
16:51:39,691 INFO [org.hibernate.orm.connections.pooling] (default task-3) HHH10001003: Autocommit mode: false
16:51:39,695 INFO [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (default task-3) HHH000115: Hibernate connection pool size: 20 (min=1)
16:51:39,803 INFO [org.hibernate.dialect.Dialect] (default task-3) HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
16:51:40,086 INFO [org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl] (default task-3) HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
16:51:40,091 INFO [org.hibernate.type.BasicTypeRegistry] (default task-3) HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#60f81f2e
16:51:40,453 INFO [org.hibernate.tool.schema.internal.SchemaCreatorImpl] (default task-3) HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#4788a59c'
16:51:40,642 INFO [stdout] (default task-3) 0,5
16:51:40,649 INFO [stdout] (default task-3) 1
16:51:40,681 WARN [org.hibernate.hql.internal.QuerySplitter] (default task-3) HHH000183: no persistent classes found for query class: FROM org.declercq.reportbuilderback.models.User
16:51:40,684 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (default task-3) HHH000397: Using ASTQueryTranslatorFactory
16:51:40,692 INFO [stdout] (default task-3) 2
16:51:40,693 INFO [stdout] (default task-3) 3
16:51:40,695 INFO [stdout] (default task-3) 5
16:51:40,696 INFO [stdout] (default task-3) Now here
16:51:40,697 INFO [stdout] (default task-3) Size: 0
The problem is in those last few lines of console output.
As you can see in my code (the DAO method and the webservice code), I put some system.out.println statements in between to troubleshoot.
All calls are being executed, no errors are thrown. Nevertheless, when I print the size of the resulting list of the database query, it is empty (size 0).
I put some data in that users table and checked manually that the data is there. Nevertheless my code is not retrieving it...
Also, why am I seeing this:
16:51:40,681 WARN [org.hibernate.hql.internal.QuerySplitter] (default task-3) HHH000183: no persistent classes found for query class: FROM org.declercq.reportbuilderback.models.User
I have a mapping in my hibernate config file, I have the annotations in place in the model class User.java, nevertheless it seems that something is missing?
If I replace the query with "From User", then I get an error stating that User is not mapped, but it is in my configuration file? I am forced to use the full package+class name in my HQL query?
Can anyone shed some light on this for me?
Thanks!
Try
allUsers = session.createQuery("SELECT u FROM User u").getResultList();
Please check this link: Hibernate: no persistent classes found for query class: SELECT p FROM entity.Presentation p
As mentioned name of the entity defaults to the simple class name. It does not contain name of the package.
You should use #Entity on User:
#Entity
public class User {
...
}
https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html
Since monday the error occurs, that the data schema is no longer exported correctly. The database tables are not created, even though there are no errors visible in the console log. This error also occures in earlier versions that ran perfectly fine before monday. Also newly created projects with maven have the same problem.
Furthermore, I installed the local WildFly server anew and also tried older versions (WildFly 8.x and 9.x).
The database in use is a mySQL database, but I also tried with other database types like H2 without any success.
The persistence.xml is as follows:
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/chargingTransactionWarehouse</jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.globally_quoted_identifiers" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
The console output:
19:09:30,499 INFO [org.jboss.modules] (main) JBoss Modules version 1.4.3.Final
19:09:30,705 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
19:09:30,781 INFO [org.jboss.as] (MSC service thread 1-6) WFLYSRV0049: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) starting
19:09:31,946 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 21) WFLYCTL0028: Attribute 'job-repository-type' in the resource at address '/subsystem=batch' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
19:09:31,954 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 7) WFLYCTL0028: Attribute 'enabled' in the resource at address '/subsystem=datasources/data-source=ExampleDS' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
19:09:31,968 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 7) WFLYCTL0028: Attribute 'enabled' in the resource at address '/subsystem=datasources/data-source=java:jboss/datasources/chargingTransactionWarehouse' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
19:09:31,969 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 7) WFLYCTL0028: Attribute 'enabled' in the resource at address '/subsystem=datasources/data-source=java:jboss/datasources/ChargingTransactionWarehouse' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
19:09:31,972 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 7) WFLYCTL0028: Attribute 'enabled' in the resource at address '/subsystem=datasources/data-source=CrowdStrom' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
19:09:31,992 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found chargingTransactionWarehouse.war in deployment directory. To trigger deployment create a file called chargingTransactionWarehouse.war.dodeploy
19:09:32,026 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
19:09:32,064 INFO [org.xnio] (MSC service thread 1-6) XNIO version 3.3.1.Final
19:09:32,073 INFO [org.xnio.nio] (MSC service thread 1-6) XNIO NIO Implementation Version 3.3.1.Final
19:09:32,127 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
19:09:32,143 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
19:09:32,146 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
19:09:32,149 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
19:09:32,151 INFO [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
19:09:32,152 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
19:09:32,161 INFO [org.jboss.as.security] (MSC service thread 1-8) WFLYSEC0001: Current PicketBox version=4.9.2.Final
19:09:32,186 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
19:09:32,215 INFO [org.jboss.as.connector] (MSC service thread 1-2) WFLYJCA0009: Starting JCA Subsystem (IronJacamar 1.2.5.Final)
19:09:32,253 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
19:09:32,265 INFO [org.jboss.as.mail.extension] (MSC service thread 1-4) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
19:09:32,267 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0018: Started Driver service with driver-name = h2
19:09:32,275 INFO [org.jboss.as.naming] (MSC service thread 1-2) WFLYNAM0003: Starting Naming Service
19:09:32,274 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0003: Undertow 1.2.9.Final starting
19:09:32,294 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0003: Undertow 1.2.9.Final starting
19:09:32,748 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path C:\Users\crowdstrom\wildfly-9.0.2.Final/welcome-content
19:09:32,758 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 4.0.9.Final
19:09:32,784 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0012: Started server default-server.
19:09:32,835 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0018: Host default-host starting
19:09:32,989 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0006: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
19:09:33,102 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
19:09:33,192 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "mysql-connector-java-5.1.38-bin.jar" (runtime-name: "mysql-connector-java-5.1.38-bin.jar")
19:09:33,192 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0027: Starting deployment of "chargingTransactionWarehouse.war" (runtime-name: "chargingTransactionWarehouse.war")
19:09:33,244 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) WFLYDS0013: Started FileSystemDeploymentService for directory C:\Users\crowdstrom\wildfly-9.0.2.Final\standalone\deployments
19:09:33,431 INFO [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBoss Web Services - Stack CXF Server 5.0.0.Final
19:09:33,617 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
19:09:33,619 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
19:09:33,640 INFO [org.jboss.as.jpa] (MSC service thread 1-8) WFLYJPA0002: Read persistence.xml for primary
19:09:33,642 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.38-bin.jar_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1
19:09:33,647 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.38-bin.jar_com.mysql.jdbc.Driver_5_1
19:09:33,660 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/ChargingTransactionWarehouse]
19:09:33,661 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/CrowdStrom]
19:09:33,661 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/chargingTransactionWarehouse]
19:09:33,699 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 58) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'chargingTransactionWarehouse.war#primary'
19:09:33,722 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 58) HHH000204: Processing PersistenceUnitInfo [
name: primary
...]
19:09:33,725 INFO [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0003: Processing weld deployment chargingTransactionWarehouse.war
19:09:33,787 INFO [org.hibernate.Version] (ServerService Thread Pool -- 58) HHH000412: Hibernate Core {4.3.10.Final}
19:09:33,790 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 58) HHH000206: hibernate.properties not found
19:09:33,792 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 58) HHH000021: Bytecode provider name : javassist
19:09:33,809 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-8) HV000001: Hibernate Validator 5.1.3.Final
19:09:34,043 INFO [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0006: Starting Services for CDI deployment: chargingTransactionWarehouse.war
19:09:34,081 INFO [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 2.2.16 (SP1)
19:09:34,105 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0009: Starting weld service for deployment chargingTransactionWarehouse.war
19:09:34,531 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 58) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'chargingTransactionWarehouse.war#primary'
19:09:34,599 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 58) HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
19:09:34,946 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 58) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
19:09:34,983 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 58) HHH000397: Using ASTQueryTranslatorFactory
19:09:35,097 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 58) HHH000227: Running hbm2ddl schema export
19:09:35,103 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 58) HHH000230: Schema export complete
19:09:35,812 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 61) Mojarra 2.2.12-jbossorg-2 20150729-1131 für Kontext '/chargingTransactionWarehouse' wird initialisiert.
19:09:36,351 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 61) WFLYUT0021: Registered web context: /chargingTransactionWarehouse
19:09:36,408 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "mysql-connector-java-5.1.38-bin.jar" (runtime-name : "mysql-connector-java-5.1.38-bin.jar")
19:09:36,408 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "chargingTransactionWarehouse.war" (runtime-name : "chargingTransactionWarehouse.war")
19:09:36,835 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
19:09:36,836 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
19:09:36,836 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) started in 6618ms - Started 350 of 536 services (229 services are lazy, passive or on-demand)
I would be grateful for any helpful answer
King regards
EDIT:
I also tried to use the <class> tags as well as trying different mySQL dialects.
Found the error!
Due to the new JVM version, the actual error was not posted and the server was started. By installing the previous JVM version, the server failed to start and the chargingTransactionWarehouse.war.failure showed that there was a mapping error...
I am new to J2EE. I am trying to connect to datasource created in jboss AS 7 using JNDI.
I am using Jboss AS 7 Standalone server to deploy my project NewDB.war.
I have created fallowing data source java:jboss/datasources/oracleDS (which is my JNDI name) in Jboss AS 7 and successfully connected to Oracle database.
I am using oracle database to store my sql tables.
I am getting fallowing error message in eclipse. but i got success message in command propmpt.
I created Dynamic web project in eclipse for performing all these tasks.I am not sure which type of project to create for my task. Correct me if i am wrong.
It will be great help if anyone helps getting out of this error.
09:53:18,418 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA
09:53:19,421 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
09:53:19,495 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
09:53:22,118 INFO [org.xnio] XNIO Version 3.0.3.GA
09:53:22,118 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
09:53:22,122 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
09:53:22,137 INFO [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
09:53:22,184 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
09:53:22,200 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
09:53:22,215 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
09:53:22,200 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
09:53:22,200 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
09:53:22,200 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
09:53:22,200 INFO [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
09:53:22,340 INFO [org.jboss.as.naming] (MSC service thread 1-7) JBAS011802: Starting Naming Service
09:53:22,356 INFO [org.jboss.as.security] (MSC service thread 1-1) JBAS013100: Current PicketBox version=4.0.7.Final
09:53:22,403 INFO [org.jboss.as.connector] (MSC service thread 1-7) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
09:53:22,465 INFO [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default]
09:53:22,559 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
09:53:23,394 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-8) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080
09:53:23,564 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
09:53:23,642 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-5) JBoss Web Services - Stack CXF Server 4.0.2.GA
09:53:24,126 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) JBAS015012: Started FileSystemDeploymentService for directory C:\Users\patillat\jboss-as-7.1.1.Final\standalone\deployments
09:53:24,142 WARN [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015002: Deployment of 'NewDBEAR.ear' requested, but the deployment is not present
09:53:24,158 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found NewDB.war in deployment directory. To trigger deployment create a file called NewDB.war.dodeploy
09:53:24,173 INFO [org.jboss.as.remoting] (MSC service thread 1-1) JBAS017100: Listening on localhost/127.0.0.1:4447
09:53:24,173 INFO [org.jboss.as.remoting] (MSC service thread 1-4) JBAS017100: Listening on localhost/127.0.0.1:9999
09:53:24,361 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "NewDB.war"
09:53:25,159 INFO [org.jboss.web] (MSC service thread 1-7) JBAS018210: Registering web context: /NewDB
09:53:25,177 INFO [org.jboss.as] (MSC service thread 1-2) JBAS015951: Admin console listening on http://127.0.0.1:9990
09:53:25,179 INFO [org.jboss.as] (MSC service thread 1-2) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 8275ms - Started 174 of 251 services (76 services are passive or on-demand)
09:53:25,305 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "NewDB.war"
09:53:26,815 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) Error getting DS : javax.naming.NameNotFoundException: datasources/oracleDS -- service jboss.naming.context.java.jboss.datasources.oracleDS
09:53:26,817 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) javax.naming.NameNotFoundException: datasources/oracleDS -- service jboss.naming.context.java.jboss.datasources.oracleDS
09:53:26,817 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
09:53:26,817 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
09:53:26,817 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
09:53:26,817 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at p1.TestServlet.init(TestServlet.java:37)
09:53:26,833 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at javax.servlet.GenericServlet.init(GenericServlet.java:242)
09:53:26,833 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202)
09:53:26,833 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:952)
09:53:26,833 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:188)
09:53:26,833 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
09:53:26,833 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
09:53:26,849 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
09:53:26,849 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
09:53:26,849 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
09:53:26,849 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
09:53:26,849 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
09:53:26,864 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
09:53:26,864 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
09:53:26,864 ERROR [stderr] (http-localhost-127.0.0.1-8080-3) at java.lang.Thread.run(Unknown Source)
javax.naming.NameNotFoundException
but i am getting success report in command prompt as fallows
16:53:33,981 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA
16:53:34,215 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
16:53:34,262 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
16:53:35,452 INFO [org.xnio] XNIO Version 3.0.3.GA
16:53:35,455 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
16:53:35,486 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
16:53:35,540 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
16:53:35,541 INFO [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
16:53:35,582 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
16:53:35,576 INFO [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
16:53:35,748 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
16:53:35,739 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
16:53:35,722 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
16:53:35,707 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
16:53:35,690 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
16:53:35,924 INFO [org.jboss.as.security] (MSC service thread 1-4) JBAS013100: Current PicketBox version=4.0.7.Final
16:53:35,906 INFO [org.jboss.as.mail.extension] (MSC service thread 1-7) JBAS015400: Bound mail session [java:jboss/mail/Default]
16:53:35,885 INFO [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service
16:53:35,817 INFO [org.jboss.as.connector] (MSC service thread 1-8) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
16:53:36,479 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-4) JBoss Web Services - Stack CXF Server 4.0.2.GA
16:53:36,679 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) JBAS015012: Started FileSystemDeploymentService for directory C:\jboss\standalone\deployments
16:53:37,242 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
16:53:38,059 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-5) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
16:53:38,059 INFO [org.apache.coyote.ajp.AjpProtocol] (MSC service thread 1-4) Starting Coyote AJP/1.3 on ajp--127.0.0.1-8009
16:53:38,106 INFO [org.jboss.as.remoting] (MSC service thread 1-6) JBAS017100: Listening on /127.0.0.1:4447
16:53:38,106 INFO [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on /127.0.0.1:9999
16:53:38,371 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.ojdbc6_jar (missing) dependents: [service jboss.data-source.java:jboss/datasources/oracleDS]
16:53:38,434 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "NewDB.war"
16:53:38,434 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "ojdbc6.jar"
16:53:39,075 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 11.2)
16:53:39,075 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010400: Bound data source [java:jboss/datasources/oracleDS]
16:53:39,184 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /NewDB
16:53:39,200 INFO [org.jboss.as] (MSC service thread 1-4) JBAS015951: Admin console listening on http://127.0.0.1:9990
16:53:39,215 INFO [org.jboss.as] (MSC service thread 1-4) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 5516ms - Started 201 of 281 services (78 services are passive or on-demand)
16:53:39,262 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "ojdbc6.jar"
16:53:39,262 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "NewDB.war"
16:53:39,262 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014776: Newly corrected services:
service jboss.jdbc-driver.ojdbc6_jar (no longer required)
16:53:55,446 INFO [stdout] (http--127.0.0.1-8080-2) **Success getting DS** : class org.jboss.jca.adapters.jdbc.WrapperDataSource
16:57:40,076 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment NewDB.war in 81ms
I wrote fallowing code in Servlet... in eclipse luna.
package p1;
import java.io.IOException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
* Servlet implementation class TestServlet
*/
#WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
public void init() throws ServletException {
super.init();
DataSource ds = null;
Context ctx = null;
try {
String strDSName = "java:jboss/datasources/oracleDS";
ctx = new InitialContext();
Context cx = (Context)ctx.lookup("java:jboss");
ds = (javax.sql.DataSource)cx.lookup("datasources/oracleDS");
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.println("Success getting DS : " + ds.getClass());
} catch (Exception e) {
System.err.println("Error getting DS : " + e);
e.printStackTrace();
}
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
Fallowing are the context.xml and web.xml placed in WebContent/META-INF and WebContent/WEB-INF/lib respectively
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/JNDI">
<Resource name="jdbc/oracleDS" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="system" password="Evergren$12" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:ORCL" />
</Context>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<resource-ref>
<description>oracle Datasource example</description>
<res-ref-name>jdbc/oracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
Your context.xml file will be ignored as that is a Tomcat configuration file and you're running JBoss AS;
Your web.xml is badly formed and I'm surprised it does not result in a deployment error - at the very least it is likely ignored;
I believe that your code works from the command line because the deployment order changes subtly. When you run from Eclipse your webapp is being initialised before your datasource, probably because of explicit deployment instructions from Eclipse.
Normally, JBoss AS can work out the correct deployment order by analysing annotations or deployment descriptors. However you don't have either in a useable form.
As this is a JavaEE 6 compliant server, you should not need explicit JNDI lookups. Try the following instead:
package p1;
import java.io.IOException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
* Servlet implementation class TestServlet
*/
#WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
#Resource(lookup="java:jboss/datasources/oracleDS")
private DataSource ds;
/**
* #see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
public void init() throws ServletException {
super.init();
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
System.out.println("Success getting DS : " + ds.getClass());
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
Here is my WebSocket endpoint
import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.twitter.hbc.core.Client;
#ServerEndpoint("/tweets")
public class TweetStreamServer {
private static final Logger LOGGER = LoggerFactory.getLogger(TweetStreamServer.class);
#OnMessage
public void tweets(final String message, final Session client) throws IOException, InterruptedException {
LOGGER.debug("registering search term {}", message);
final TwitterHoseBird twitterHoseBird = new TwitterHoseBird();
final Client twitterClient = twitterHoseBird.getInstance(message);
while(!twitterClient.isDone()) {
client.getAsyncRemote().sendText(twitterHoseBird.getMsgQueue().take());
}
}
#OnClose
public void onClose(CloseReason reason) {
System.out.println("Closing connection");
LOGGER.warn("closing connection {}", reason);
}
}
When I deploy this, I try to hit the endpoint via JavaScript code as
var connection = new WebSocket('ws://127.0.0.1:8080/tweetstream-1.0-SNAPSHOT/tweets');
connection.onmessage = function (e) {
console.log('Server: ' + e.data);
};
connection.send('fifa');
This starts to send tweets from the server. Now when I close the connection from client, I do
connection.close();
Problem?
I want to close connection to twitter once websocket client connection closes. I expect the following code to execute
#OnClose
public void onClose(CloseReason reason) {
System.out.println("Closing connection");
LOGGER.warn("closing connection {}", reason);
}
But on server log, I do not see any such statement
/Users/harith/code/installers/wildfly-8.1.0.Final/bin/standalone.sh
=========================================================================
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java -classpath "/Applications/IntelliJ IDEA 13.app/lib/idea_rt.jar:/Applications/IntelliJ IDEA 13.app/lib/util.jar" -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper /private/var/folders/qs/y62p93xs0bdb9ptk6l2r8vw0002kvk/T/classpath571663656928489966.tmp com.intellij.javaee.oss.process.JavaeeProcess 53801 com.intellij.javaee.oss.jboss.agent.JBoss71Agent
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
JBoss Bootstrap Environment
[2014-07-12 02:16:06,305] Artifact tweetstream:war: Server is not connected. Deploy is not available.
JBOSS_HOME: /Users/harith/code/installers/wildfly-8.1.0.Final
Detected server admin port: 9990
Detected server http port: 8080
JAVA: /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java
JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
=========================================================================
[0m14:16:06,048 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final
[0m[0m14:16:06,289 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.2.Final
[0m[0m14:16:06,349 INFO [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.1.0.Final "Kenny" starting
[0m[0m14:16:07,165 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
[0m[0m14:16:07,180 INFO [org.xnio] (MSC service thread 1-8) XNIO version 3.2.2.Final
[0m[0m14:16:07,186 INFO [org.xnio.nio] (MSC service thread 1-8) XNIO NIO Implementation Version 3.2.2.Final
[0m[0m14:16:07,207 INFO [org.jboss.as.security] (ServerService Thread Pool -- 45) JBAS013171: Activating Security Subsystem
[0m[33m14:16:07,208 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 46) JBAS010153: Node identifier property is set to the default value. Please make sure it is unique.
[0m[0m14:16:07,211 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 32) JBAS010280: Activating Infinispan subsystem.
[0m[0m14:16:07,213 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 31) WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors
[0m[0m14:16:07,219 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 40) JBAS011800: Activating Naming Subsystem
[0m[0m14:16:07,221 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
[0m[0m14:16:07,222 INFO [org.jboss.as.security] (MSC service thread 1-13) JBAS013170: Current PicketBox version=4.0.21.Beta1
[0m[0m14:16:07,222 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 38) JBAS012615: Activated the following JSF Implementations: [main]
[0m[0m14:16:07,251 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017502: Undertow 1.0.15.Final starting
[0m[0m14:16:07,252 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017502: Undertow 1.0.15.Final starting
[0m[0m14:16:07,266 INFO [org.jboss.as.connector.logging] (MSC service thread 1-11) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.5.Final)
[0m[0m14:16:07,291 INFO [org.jboss.remoting] (MSC service thread 1-8) JBoss Remoting version 4.0.3.Final
[0m[0m14:16:07,291 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
[0m[0m14:16:07,299 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) JBAS010417: Started Driver service with driver-name = h2
[0m[0m14:16:07,346 INFO [org.jboss.as.naming] (MSC service thread 1-15) JBAS011802: Starting Naming Service
[0m[0m14:16:07,346 INFO [org.jboss.as.mail.extension] (MSC service thread 1-13) JBAS015400: Bound mail session [java:jboss/mail/Default]
[0m[0m14:16:07,390 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017527: Creating file handler for path /Users/harith/code/installers/wildfly-8.1.0.Final/welcome-content
[0m[0m14:16:07,425 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017525: Started server default-server.
[0m[0m14:16:07,498 INFO [org.wildfly.extension.undertow] (MSC service thread 1-13) JBAS017531: Host default-host starting
[0m[0m14:16:07,561 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017519: Undertow HTTP listener default listening on /127.0.0.1:8080
[0m[0m14:16:07,724 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-13) JBAS015012: Started FileSystemDeploymentService for directory /Users/harith/code/installers/wildfly-8.1.0.Final/standalone/deployments
[0m[0m14:16:07,728 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "4f0c2559-5f61-4cf1-b441-c6288b419b80.war" (runtime-name: "4f0c2559-5f61-4cf1-b441-c6288b419b80.war")
[0m[0m14:16:07,736 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
[0m[0m14:16:07,918 INFO [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.4.Final
[0m[0m14:16:08,062 INFO [io.undertow.websockets.jsr] (MSC service thread 1-11) UT026003: Adding annotated server endpoint class com.self.tweetstream.TweetStreamServer for path /tweets
[0m[0m14:16:08,075 INFO [io.undertow.websockets.jsr] (MSC service thread 1-11) UT026004: Adding annotated client endpoint class com.self.tweetstream.TweetStreamClient
[0m[0m14:16:08,167 INFO [org.wildfly.extension.undertow] (MSC service thread 1-11) JBAS017534: Registered web context: /4f0c2559-5f61-4cf1-b441-c6288b419b80
[0m[0m14:16:08,203 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "4f0c2559-5f61-4cf1-b441-c6288b419b80.war" (runtime-name : "4f0c2559-5f61-4cf1-b441-c6288b419b80.war")
[0m[0m14:16:08,215 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
[0m[0m14:16:08,215 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
[0m[0m14:16:08,216 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 2554ms - Started 250 of 304 services (91 services are lazy, passive or on-demand)
[0mConnected to server
[2014-07-12 02:16:08,683] Artifact tweetstream:war: Artifact is being deployed, please wait...
[0m14:16:08,794 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "tweetstream-1.0-SNAPSHOT.war" (runtime-name: "tweetstream-1.0-SNAPSHOT.war")
[0m[0m14:16:09,408 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016002: Processing weld deployment tweetstream-1.0-SNAPSHOT.war
[0m[0m14:16:09,450 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-5) HV000001: Hibernate Validator 5.1.0.Final
[0m[0m14:16:09,548 INFO [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016005: Starting Services for CDI deployment: tweetstream-1.0-SNAPSHOT.war
[0m[0m14:16:09,573 INFO [org.jboss.weld.Version] (MSC service thread 1-14) WELD-000900: 2.1.2 (Final)
[0m[0m14:16:09,580 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment tweetstream-1.0-SNAPSHOT.war
[0m[0m14:16:10,361 INFO [io.undertow.websockets.jsr] (MSC service thread 1-8) UT026004: Adding annotated client endpoint class com.self.tweetstream.TweetStreamClient
[0m[0m14:16:10,364 INFO [io.undertow.websockets.jsr] (MSC service thread 1-8) UT026003: Adding annotated server endpoint class com.self.tweetstream.TweetStreamServer for path /tweets
[0m[0m14:16:10,383 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-8) Initializing Mojarra 2.2.6-jbossorg-4 20140501-1134 for context '/tweetstream-1.0-SNAPSHOT'
[0m[0m14:16:11,293 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017534: Registered web context: /tweetstream-1.0-SNAPSHOT
[0m[0m14:16:11,307 INFO [org.jboss.as.server] (management-handler-thread - 2) JBAS018559: Deployed "tweetstream-1.0-SNAPSHOT.war" (runtime-name : "tweetstream-1.0-SNAPSHOT.war")
[0m[2014-07-12 02:16:11,327] Artifact tweetstream:war: Artifact is deployed successfully
[2014-07-12 02:16:11,327] Artifact tweetstream:war: Deploy took 2,644 milliseconds
[0m14:16:21,124 INFO [com.twitter.hbc.httpclient.BasicClient] (default task-2) New connection executed: tweetStream-client, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true
[0m[0m14:16:21,207 INFO [com.twitter.hbc.httpclient.ClientBase] (hosebird-client-io-thread-0) tweetStream-client Establishing a connection
[0m[0m14:16:23,789 INFO [com.twitter.hbc.httpclient.ClientBase] (hosebird-client-io-thread-0) tweetStream-client Processing connection data
[0m
What am I missing here?
UPDATE
I have test as following
#Test
public void test() throws URISyntaxException, IOException, DeploymentException, InterruptedException {
System.out.println("URI: " + getEndpointUrl());
TweetStreamClient.latch = new CountDownLatch(1);
Session session = connectToServer(TweetStreamClient.class, "tweets");
assertNotNull(session);
// (todo: harit) assert correct things
// assertTrue(TweetStreamClient.latch.await(10, TimeUnit.SECONDS));
// assertEquals("Hello", TweetStreamClient.response);
}
When I run this test, I see following in logs
8295 [main] INFO io.undertow.websockets.jsr - UT026004: Adding annotated client endpoint class com.self.tweetstream.TweetStreamClient
14:59:26,981 INFO [org.wildfly.extension.undertow] (MSC service thread 1-13) JBAS017535: Unregistered web context: /b5b7b561-8b49-4c69-b55f-7859b86da36d
14:59:26,983 INFO [stdout] (default task-2) session id:AMAjTU1TYTCjXBgLOKnMXS6q, search term: Hello World!
14:59:26,985 INFO [stdout] (default task-2) Closing session: io.undertow.websockets.jsr.UndertowSession#cd7ecfa
14:59:26,986 WARN [com.self.tweetstream.TweetStreamServer] (default task-2) closing session: AMAjTU1TYTCjXBgLOKnMXS6q, reason: CloseReason[1001]
But when I call connection.close() from JavaScript, I do not see such thing
I was experiencing the same problem and initially thought it was a Wildfly issue, but then noticed that Firefox was triggering #OnClose. When I added an #OnError, Chromium was triggering that.
I found an another StackOverflow question referring to the same behavior.
It also appears that Chromium may have just fixed this issue as of a month ago.
I am trying to setup a simple project, where I have a REST service query a database using JPA/Hibernate. My platform is Windows, MySQL 5.6, and JBoss (Wildfly) 8 with hibernate 4.3. My project setup:
PersonApp (Eclipse Java Enterprise Project) >PersonApp.ear
-PersonData (Eclipse JPA Project) >PersonData.jar
-PersonRest (Eclipse Dynamic Web Project) >PersonRest.war
PersonData project contains 1 entity class (Person.java), a manager class for peforming the em.find and em.persist through EntityManager (PersonManager.java), and persistance.xml
PersonRest project contains one REST service, with one GET method, which calls the PersonManager class to query all Persons.
PersonApp is just a container project which includes PersonData and PersonRest as modules.
Now for the issue: I deploy PersonApp.ear to Wildfly 8 (JBoss), and navigate to the service URL in a web browser. PersonRest service calls PersonManager class, which calls Persistence.createEntityManagerFactor("PersonData"); This line returns 'null' and I have no idea why.
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="PersonData" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
<class>com.csc.data.Person</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
Wildfly startup output (shows app deployment, data source loaded, persistence unit):
14:31:14,607 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final
14:31:14,841 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.0.Final
14:31:14,919 INFO [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Final "WildFly" starting
14:31:15,871 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found PersonApp.ear in deployment directory. To trigger deployment create a file called PersonApp.ear.dodeploy
14:31:15,887 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
14:31:15,903 INFO [org.xnio] (MSC service thread 1-8) XNIO version 3.2.0.Final
14:31:15,919 INFO [org.xnio.nio] (MSC service thread 1-8) XNIO NIO Implementation Version 3.2.0.Final
14:31:15,934 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.
14:31:15,950 INFO [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem
14:31:15,966 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension
14:31:15,997 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017502: Undertow 1.0.0.Final starting
14:31:15,997 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Final starting
14:31:15,997 INFO [org.jboss.as.security] (MSC service thread 1-2) JBAS013170: Current PicketBox version=4.0.20.Final
14:31:15,997 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem
14:31:15,997 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main]
14:31:16,028 INFO [org.jboss.as.connector.logging] (MSC service thread 1-5) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.3.Final)
14:31:16,075 INFO [org.jboss.as.naming] (MSC service thread 1-5) JBAS011802: Starting Naming Service
14:31:16,075 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
14:31:16,090 INFO [org.jboss.as.mail.extension] (MSC service thread 1-6) JBAS015400: Bound mail session [java:jboss/mail/Default]
14:31:16,106 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
14:31:16,106 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010417: Started Driver service with driver-name = h2
14:31:16,106 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010417: Started Driver service with driver-name = com.mysql
14:31:16,184 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path C:\wildfly-8.0.0.Final/welcome-content
14:31:16,200 INFO [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version 4.0.0.Final
14:31:16,434 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017525: Started server default-server.
14:31:16,543 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017531: Host default-host starting
14:31:16,605 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
14:31:16,652 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/MySqlDS]
14:31:16,730 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "PersonApp.ear" (runtime-name: "PersonApp.ear")
14:31:16,746 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) JBAS015012: Started FileSystemDeploymentService for directory C:\wildfly-8.0.0.Final\standalone\deployments
14:31:16,761 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
14:31:16,824 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "null" (runtime-name: "PersonRest.war")
14:31:16,855 INFO [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final
14:31:16,870 INFO [org.jboss.as.jpa] (MSC service thread 1-3) JBAS011401: Read persistence.xml for PersonData
14:31:16,933 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 1 of 2) Service 'PersonApp.ear#PersonData'
14:31:16,948 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 52) HHH000204: Processing PersistenceUnitInfo [
name: PersonData
...]
14:31:16,996 INFO [org.hibernate.Version] (ServerService Thread Pool -- 52) HHH000412: Hibernate Core {4.3.1.Final}
14:31:17,012 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000206: hibernate.properties not found
14:31:17,012 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000021: Bytecode provider name : javassist
14:31:17,152 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'PersonApp.ear#PersonData'
14:31:17,277 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 52) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
14:31:17,511 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 52) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
14:31:17,589 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 52) HHH000397: Using ASTQueryTranslatorFactory
14:31:17,620 INFO [org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 52) HV000001: Hibernate Validator 5.0.3.Final
14:31:17,885 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 52) HHH000227: Running hbm2ddl schema export
14:31:17,932 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 52) HHH000230: Schema export complete
14:31:18,197 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-2) Deploying javax.ws.rs.core.Application: class com.csc.rest.service.PersonRest
14:31:18,197 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-2) Adding singleton resource com.csc.rest.service.PersonService from Application class com.csc.rest.service.PersonRest
14:31:18,323 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017534: Registered web context: /PersonRest
14:31:18,370 INFO [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "PersonApp.ear" (runtime-name : "PersonApp.ear")
14:31:18,417 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
14:31:18,417 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
14:31:18,417 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final "WildFly" started in 4059ms - Started 291 of 351 services (98 services are lazy, passive or on-demand)
Wildfly output on REST service call:
14:32:06,221 INFO [org.hibernate.jpa.internal.util.LogHelper] (default task-2) HHH000204: Processing PersistenceUnitInfo [
name: PersonData
...]
14:32:06,236 INFO [org.hibernate.dialect.Dialect] (default task-2) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
14:32:06,236 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (default task-2) HHH000397: Using ASTQueryTranslatorFactory
14:32:06,252 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (default task-2) HHH000227: Running hbm2ddl schema export
14:32:06,268 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (default task-2) HHH000230: Schema export complete
14:32:06,300 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /PersonRest/PersonService: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.6.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_51]
Caused by: java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:76) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:118) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1602) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:210) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:91) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:345) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:313) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at com.csc.data.PersonManager.openConnection(PersonManager.java:51) [PersonData.jar:]
at com.csc.rest.service.PersonService.getAllPersons(PersonService.java:21) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_51]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:280) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:234) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:221) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.6.Final.jar:]
... 29 more
It looks like Wildfly is able to find persistance.xml, and it is able to connect to the MySQL database (it even drops the table data as expected). It shows in the output that it found the persistence unit PersonData. I even tried changing the provider to something off the wall just to see if it would error. It did error saying it couldn't find the provider class. I changed it back and the error went away, so I assume it is able to find the provider. What am I missing?
I found the solution. In my REST service, I was instantiating the PersonManager class myself. Instead, I needed to inject it with #Inject. After this, it worked, almost. I then had a problem getting CDI to work inside a RESTeasy REST service, but that was a separate issue. More details can be found here in my JBoss community thread: https://community.jboss.org/message/863014#863014