jboss wildfly, error with jpacontainer

I’m trying a very simple program to learn vaading. It works with tomcat 7 but fails with jboss wildfly.
I have created this entity:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity @Table(name="employee")
public class Employee {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "id")
    private int id;
    
    @NotNull
    @Size(min=3, max=50)
    private String name;
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Override
    public String toString() {
        return name;
    }
}

The class I request:

import javax.servlet.annotation.WebServlet;
import com.vaadin.addon.jpacontainer.JPAContainer;
import com.vaadin.addon.jpacontainer.JPAContainerFactory;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("jpacontainerexercise1")
public class Jpacontainerexercise1UI extends UI {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = Jpacontainerexercise1UI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        JPAContainer<Employee> jpac = JPAContainerFactory.make(Employee.class, "exercice1");
        Employee em = new Employee();
        em.setName("ThisIsMyName");
        int id = (Integer) jpac.addEntity(em);
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);
        layout.addComponent(new Label("Name: " + em.getName()));
        layout.addComponent(new Label("ID: " + id));
        Table personTable = new Table("The Persistent People", jpac);
        personTable.setVisibleColumns(new Object[]{"id","name"});
        layout.addComponent(personTable);

    }
}

Than added this to ivy.xml

<dependency org="com.vaadin.addon" name="jpacontainer" rev="3.1.1"/>
<dependency org="org.eclipse.persistence" name="eclipselink" rev="2.4.2"/>
<dependency org="org.eclipse.persistence" name="javax.persistence" rev="2.1.0"/>
<dependency org="javax.validation" name="validation-api" rev="1.1.0.Final"/>    
<dependency org="org.hibernate" name="hibernate-validator" rev="5.1.0.Final"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.6"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.30"/>

The persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="exercice1">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.MySQLPlatform" />
            <property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="eclipselink.jdbc.url" value="jdbc:mysql://localhost/exercise1" />
            <property name="eclipselink.jdbc.user" value="root" />
            <property name="eclipselink.jdbc.password" value="pwd" />
            <property name="eclipselink.logging.level" value="FINE" />
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
            <property name="eclipselink.ddl-generation.output-mode" value="database" />
        </properties>
    </persistence-unit>
</persistence

Everything else is the default created by Eclipse vaadin plug-in.
It runs fine with tomcat, showing lables and table (db table is correctely populated). With jboss I get this error:

Context Path: jpacontainerexercise1 Servlet Path: Path Info: / Query String: v-browserDetails=1&theme=jpacontainerexercise1&v-sh=1200&v-sw=1920&v-cw=947&v-ch=629&v-curdate=1397043691201&v-tzo=-120&v-dstd=60&v-rtzo=-60&v-dston=true&v-vw=947&v-vh=0&v-loc=http%3A%2F%2Flocalhost%3A8080%2Fjpacontainerexercise1%2F&v-wn=jpacontainerexercise1-863496467-0.9144240031028977&v-1397043691202 Stack Trace javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: Object: ThisIsMyName is not a known entity type. com.vaadin.server.VaadinServlet.service(VaadinServlet.java:240) javax.servlet.http.HttpServlet.service(HttpServlet.java:790) io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:744) Any hint on what is wrong?

Hello There,

Can you please share the format of your deployable?

If you do not wish to pls check if persistence.xml is the below path


${APP_ROOT}/WEB-INF/classes/META-INF/persistence.xml

One more thing, Jboss 7.x is modular and by default uses Hibernate 4 as the persistence provider. If you wish to use other JPA Provider like Eclipse link in your case you need to some more configs and setup.

  • Create a module for Eclipse LInk and DB Driver
  • Create a datasource in the Standalone.xml
  • Use this datasource in your persistence.xml

Pls follow the below links for further info

https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7
http://www.eclipse.org/eclipselink/documentation/2.4/solutions/jboss002.htm

Hope this solves your problem.

Thanks,
Krishna.

Maybe it could be importanti, I get the above exeption both with eclipselink 2.5.1 and 2.4.2.

Hello Mattia,

Firstly,
You have an illformed Persistence.xml pls use -

<persistence-unit name="exercice1" transaction-type="RESOURCE_LOCAL">

Try with this. I don’t have an environment at home to take a look at your Sources completely. But I checked your persistence.xml and foud the above problem.

Thanks,
Krishna

Hello Krishna,
thank you so much. The missing of RESOURSE_LOCAL was the problem. It works now. You have been very kind.
Thanks.

You are welcome! And glad that I was some help to you!

Thank you very much. The persistence.xml is in the right path, but I didn’t configure hibernate. Just to be precise, I use jboss 8 and some support of eclipselink is builtin, but some configuration is needed anyway.
I followed this link https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide

Now I get the error:

javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA.

(removed sources, reply just to keed history of my previous answare)

Hello Krishna,
I need some help still. JPA works fine when I run it on server, but I have some problem when I try to run from junit. I get the first error again. I think I’m doing it wrong. Please could you give me some hint on how test crud operation with junit test?

The test class:

import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;

import com.vaadin.addon.jpacontainer.JPAContainer;
import com.vaadin.addon.jpacontainer.JPAContainerFactory;

public class EmployeeTest {

    @Test
    public void addNewEmployee() {
        JPAContainer<Employee> jpac =
             JPAContainerFactory.make(Employee.class, "exercice1");
        Employee em = new Employee();
        em.setName("ThisIsMyName");
        int id = (Integer) jpac.addEntity(em);
        Assert.assertTrue(id > 0);
    }
  }

The error:

java.lang.IllegalArgumentException: Object: ThisIsMyName is not a known entity type.
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3495)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:377)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3466)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:497)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:474)
    at com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider$1.run(MutableLocalEntityProvider.java:141)
    at com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider.runInTransaction(MutableLocalEntityProvider.java:120)
    at com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider.addEntity(MutableLocalEntityProvider.java:137)
    at com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider.addEntity(CachingMutableLocalEntityProvider.java:164)
    at com.vaadin.addon.jpacontainer.JPAContainer.addEntity(JPAContainer.java:1113)
    at com.example.jpacontainerexercise1.EmployeeTest.addNewEmployee(EmployeeTest.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I have gone through your folder structure, Create a META-INF folder under src folder and place persistence.xml under it. BTW you don’t require classes folder to be in the classpath, unless it has a specific reason.

Thanks.

Thank you very much for the valuable help. Everything works now.
Regards.