Hot questions for Using GlassFish in eclipselink

Question:

My application runs on Payara and provides a REST API but when I try to create an object with a POST request I get the following exception:

Exception [EclipseLink-43] (Eclipse Persistence Services - 2.6.0.payara-p1): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [Miss] of type [class java.lang.String].
Descriptor: XMLDescriptor(at.htl.handballinheritance.entity.Throw --> [DatabaseTable(event), DatabaseTable(dataObject)])
  at org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:940)
  at org.eclipse.persistence.internal.oxm.QNameInheritancePolicy.classFromRow(QNameInheritancePolicy.java:278)
  ...

Full Stacktrace

On the contrary everything is fine and no errors occur when I am executing the program on Wildfly which uses Hibernate.

Entities:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@XmlRootElement
public abstract class Event extends DataObject implements Serializable {
    ... 
}

@Entity
public class Throw extends Event implements Serializable {

    @Enumerated(EnumType.STRING)
    @NotNull
    private ThrowingType type;

    ...
}

public enum ThrowingType {
    Goal, Miss
}

REST API:

@POST
public Response create(Throw entity) {
    em.persist(entity);
    return Response.created(URI.create("...")).build();
}

I think that Eclipselink has problems to unmarshal my json. Do I need any additional annotation?


Answer:

You will get this error if you use a field named "type".

Question:

I have made a converter such that when I read DATE fields out of the database, it should be able to coerce them to java.time.LocalDate objects. However, when I try to do so, it gives me this error:

 The object [3/16/17 12:00 AM], of class [class java.sql.Timestamp], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[startDate-->TEST_TABLE.START_DATE]] with descriptor [RelationalDescriptor(com.test.TestEntity --> [DatabaseTable(TEST_TABLE)])], could not be converted to [class [B].

TEST_TABLE is my table, which has a column START_DATE which is of type DATE. Here is the converter:

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.sql.Date;
import java.time.LocalDate;

@Converter(autoApply = true)
public class OracleLocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
    @Override
    public Date convertToDatabaseColumn(LocalDate attribute) {
        return (attribute != null ? Date.valueOf(attribute) : null);
    }

    @Override
    public LocalDate convertToEntityAttribute(Date dbData) {
        return (dbData != null ? dbData.toLocalDate() : null);
    }
}

Why does it think that my column is a timestamp? Do all dates in oracle get coerced to java.sql.Timestamp?


Answer:

The class java.sql.Timestamp is the one the persistence provider uses to parse a date from the DB regardless the value is just a date. It makes sense because it allows the persistence provider to get the time part of a DATETIME or a TIMESTAMP. Note that this class extends from java.util.Date not java.sql.Date.

So, updating your converter to something like this should do the trick:

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class OracleLocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {

    @Override
    public Date convertToDatabaseColumn(LocalDate attribute) {
        return attribute == null ? null : Date.from(attribute.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }

    @Override
    public LocalDate convertToEntityAttribute(Date dbData) {
        return dbData == null ? null : dbData.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }
}

Question:

I am migrating an application using EJBs with JPA (EclipseLink) from Glassfish3 to Glassfish4. Most of the is working on the new server, but for some reason this named query, where an object is instantiated within the JPQL statement, is not working:

@NamedQuery(
    name = "countByUserType", 
    query = "SELECT new org.util.CountBean(ev.user.type, count(ev.user.id)) 
             FROM Event ev WHERE ev.idTs = :idTs GROUP BY ev.user.type"
)

My class CountBean is a simple POJO class

public class CountBean{
    String label;
    Long count;
    public CountBean(String label, Long count) {
        this.label = label;
        this.count = count;
    }
}

The error message I get is below:

 Caused by: Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.QueryException
 Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
 Internal Exception: java.lang.NullPointerException
 Query: ReportQuery(name="countByUserType" referenceClass=Event jpql="SELECT new org.util.CountBean(ev.user.type, count(ev.user.idU), 0l) FROM Event ev WHERE ev.idTs = :idTs GROUP BY ev.user.type")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1584)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:680)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:888)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:613)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:341)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1107)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:522)
    at org.un.sers.repository.EventFacade.countRoomsBooked(EventFacade.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
    at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
    at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
    ... 35 more
 Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.queries.ConstructorReportItem.initialize(ConstructorReportItem.java:167)
    at org.eclipse.persistence.queries.ReportQuery.prepare(ReportQuery.java:1058)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
    ... 69 more

I would appreciate to get some insights from someone who experienced a similar issue or if there is something that seems off in the code I posted. Again, this works when I deploy the application on Glassfish 3, but not on Glassfish 4 and the database it connects to is Oracle 11g.


Answer:

This is bug in the old versions of eclipselink, check this :


Solution

The better way to solve it is to upgrade to the latest versions 2.7.1 Latest Release


Beside I would like to use Payara Server instead of GlassFish 4 Server, there are many bugs was fixed I have a good experience with this server, it is more performance and more quick than GlassFish now.

Question:

I am trying to setup a basic JPA application that creates a simple table in mySQL.

I use glassfish 4.1, I have created connection pool/resource and pinged successfully the database from administration panel.

I created a web application project which contains just one simple entity and a persistence.xml under src/META-INF folder.

<?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="DataPersistencePU" transaction-type="JTA">
 <jta-data-source>mysqlresource</jta-data-source>
 <exclude-unlisted-classes>false</exclude-unlisted-classes>
  <properties>
  <property name="javax.persistence.schema-generation.database.action"    value="create"/>
</properties>
</persistence-unit>
</persistence>

And the entity file,

 @Entity
public class DataProvider implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof DataProvider)) {
        return false;
    }
    DataProvider other = (DataProvider) object;
    if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "Entity.DataProvider[ id=" + id + " ]";
}

}

I also tried moving persistence.xml under /WEB-INF, still no cure.

There is no error in Glassfish logs. I am just trying to get eclipseLink working and automatically generate the table.


Answer:

As Dark mentioned, I created EntityManager, started a transaction and persisted a row to the table:

@WebServlet(name = "TestUsertServlet", urlPatterns = {"/TestUsertServlet"})
@PersistenceContext(
    unitName = "DataPersistencePU")
@TransactionAttribute(REQUIRED)
 public class TestUsertServlet extends HttpServlet {

@Resource
private javax.transaction.UserTransaction utx;

@PersistenceContext
EntityManager em;

protected void processRequest(HttpServletRequest request,     HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestUsertServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestUsertServlet at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try {
        utx.begin();
        TestUser testUser = new TestUser();
        em.persist(testUser);
        utx.commit();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

But would like to know why EntityManager is needed in order for the table to be created. I thought that EM has to do only with Persistence Context, the lifecycle of Entities related with the database, which means objects representing records to a table, not the table itself, right?

Question:

I have an application falling foul of the following known issue: https://github.com/eclipse-ee4j/eclipselink/pull/117

It's a bug affecting some versions of eclipselink, notably the version of eclipselink bundled with payara 5.182 which is the latest.

[2018-08-14T15:34:25.323+0200] [Payara 5.182] [INFO] [] [org.eclipse.persistence.session./file:/C:/Projects/mcp/mcp/war/target/mcp/WEB-INF/lib/integration-0.0.1-SNAPSHOT.jar_tlmon] [tid: _ThreadID=53 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1534253665323] [levelValue: 800] [[  EclipseLink, version: Eclipse Persistence Services - 2.7.1.qualifier]]   
EclipseLink, version: Eclipse Persistence Services - 2.7.1.qualifier]]

I have changed my POM.XML file to use a later version.

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.7.3</version>
</dependency>

This doesn't seem to impact the version used by payara. How do I force payara to use the fixed version of eclipse link?


Answer:

download the latest version of eclipselink: http://www.eclipse.org/eclipselink/downloads/

Replace the files in glassfish\modules with the ones above.

Question:

I have a Java EE web application and a custom realm (authentication module) for Glassfish 4 (see GlassFish Application Development Guide, II 4-6 "Creating a Custom Realm"). Both of them are using JPA, with subtle differences.

Custom realm
<persistence-unit name="AuthPU" transaction-type="JTA">
    <jta-data-source>jdbc/AuthDB</jta-data-source>
    <class>auth.User</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
  • auth.User is a technical entity that contains authentication-specific data
  • EntityManager is created with Persistence API (since no injection is available for realms)
  • META-INF/orm.xml is used to define mappings (no @Entity annotations at all)
  • the module is packaged as JAR and deployed to $GLASSFISH_HOME/glassfish/domains/domain1/lib
Application
<persistence-unit name="AppPU" transaction-type="JTA">
    <jta-data-source>jdbc/AppDB</jta-data-source>
    <class>app.User</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
  • app.User is a business entity
  • EntityManager is injected with @PersistenceContext
  • both @Entity annotations (for basic mappings) and META-INF/orm.xml file (for customization) are used
  • application is packaged and deployed in the standard way.

Upon application deployment, an exception is thrown:

Severe:   javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [AppPU] failed.
Internal Exception: Exception [EclipseLink-7237] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity name must be unique in a persistence unit. Entity name [User] is used for the entity classes [app.User] and [auth.User].

Seems like AppPU persistence unit somehow discovers entities from auth.* package (via orm.xml?) I don't want to alter entity names because it will break existing JPQL queries. How can I isolate the modules so that AppPU ignores foreign orm.xml and doesn't look into auth.* package for entities?

P.S. As you may have noticed, EclipseLink version is 2.6.0 - I've upgraded it manually. Eclipse 2.5.2 shipped with GlassFish 4.1 gave the same exception.


Answer:

Okay, I've figured out what exactly happens.

According to GlassFish Application Deployment Guide (C-13),

the web module follows the standard class loader delegation model and delegates to its parent class loader first before looking in the local class loader.

This is the default behavior which can be controlled with <class-loader> element of glassfish-web.xml. EclipseLink tries to process each and every META-INF/orm.xml it finds on classpath, and thus, picks that of the custom realm first. Even if application's orm.xml contains <xml-mapping-metadata-complete/>, it doesn't play a role, as auth.* classes are already added to the persistence unit.

There are two solutions for the problem (beside renaming entities):

  1. Use <class-loader delegate="false"/> in glassfish-web.xml;
  2. if the above is not acceptable ("for a web module that accesses EJB components or that acts as a web service client or endpoint" - Application Deployment Guide), rename custom realm's META-INF/orm.xml to something else and reflect it in persistence.xml.

Question:

I have been scouring the web for more hours than I would like to admit for a fix.

I am trying to set up an application which needs to have the following:

  • run on glassfish 5
  • use Java EE
  • use EclipseLink and JPA and automatically generate the db schema from the entities.
  • maven for dependencies.

Right now I have 4 child modules and a parent module. I have declared all the maven dependencies and even the dependencies between modules. But I cannot get the app to run properly. Here is the project folder structure:

-mitblick
--mitblick-persistence
---src.main.resources/META-INF/persistence.xml
---pom.xml
--mitblick-business
---pom.xml
--mitblick-client
---pom.xml
--mitblick-ear
---pom.xml
--pom.xml (<- parent pom) 

Here are the individual pom.xml files:

Parent pom.xml:

 <?xml version="1.0" encoding="UTF-8"?>

<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>mitblick.ro</groupId>
    <artifactId>mitblick</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <packaging>pom</packaging>
    <name>MitBlick Parent</name>
    <description>Mitblick Parent Project</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.source>1.8</java.source>
        <java.target>1.8</java.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <payara.versio>5.183.0</payara.versio>
        <jackson.jaxrs.json.version>2.9.4</jackson.jaxrs.json.version>
        <jackson.jaxrs.json.glassfish.version>2.27</jackson.jaxrs.json.glassfish.version>
        <sonar.coverage.exclusions>/**/control/*,**/dto/*,**/filter/*,**/boundary/*,**/entity/*,**/dao/*,**/exceptions/*</sonar.coverage.exclusions>

    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
            <version>LATEST</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId>
            <version>LATEST</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.directory.studio</groupId>
            <artifactId>org.apache.commons.io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>${jackson.jaxrs.json.version}</version>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>1.4.1</version>
                    <configuration>
                        <rules>
                            <dependencyConvergence/>
                        </rules>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.3.0.603</version>
                    <executions>
                        <execution>
                            <phase>verify</phase>
                            <goals>
                                <goal>sonar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.9</version>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>prepare-agent-integration</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>jacoco-site</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ejb-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <ejbVersion>3.2</ejbVersion>
                        <generateClient>true</generateClient>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.10.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <parallel>methods</parallel>
                        <threadCount>10</threadCount>
                        <includes>
                            <include>*Test</include>
                        </includes>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.surefire</groupId>
                            <artifactId>surefire-junit47</artifactId>
                            <version>2.19.1</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <!-- The normal build - active by default -->
        <profile>
            <id>normal-build</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <modules>
                <module>mitblick-persistence</module>
                <module>mitblick-business</module>
                <module>mitblick-client</module>
                <module>mitblick-ear</module>
            </modules>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Persistence pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <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>
    <parent>
        <groupId>mitblick.ro</groupId>
        <artifactId>mitblick</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>mitblick-persistence</artifactId>
    <name>Mitblick Persistence</name>
    <description>Persistence layer</description>
    <packaging>jar</packaging>
</project>

Business pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <artifactId>mitblick</artifactId>
        <groupId>mitblick.ro</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>mitblick-business</artifactId>
    <name>MitBlick Business</name>
    <description>Business layer</description>
    <packaging>ejb</packaging>

    <dependencies>
        <dependency>
            <groupId>mitblick</groupId>
            <artifactId>mitblick-persistence</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>2.17</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>2.0.2-beta</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Client pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <artifactId>mitblick</artifactId>
        <groupId>mitblick.ro</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>mitblick-client</artifactId>
    <name>MitBlick Client</name>
    <description>Client layer</description>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>mitblick.ro</groupId>
            <artifactId>mitblick-business</artifactId>
            <type>ejb</type>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

And lastly EAR pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>mitblick</artifactId>
        <groupId>mitblick.ro</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>mitblick-ear</artifactId>
    <packaging>ear</packaging>
    <name>Mitblick EAR Project</name>

    <dependencies>
        <dependency>
            <groupId>mitblick.ro</groupId>
            <artifactId>mitblick-client</artifactId>
            <type>war</type>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <version>7</version>
                    <fileNameMapping>no-version</fileNameMapping>
                    <modules>
                        <webModule>
                            <groupId>mitblick.ro</groupId>
                            <artifactId>mitblick-client</artifactId>
                            <contextRoot>mitblick</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

In my persistence module I have this persistence.xml file:

<?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="mitblick" transaction-type="JTA">
        <jta-data-source>jdbc/mitblick-persistence</jta-data-source>

        <properties>

            <property name="eclipselink.logging.level" value="FINE" />
            <property name="eclipselink.logging.parameters" value="true"/>
            <!--<property name="eclipselink.ddl-generation.output-mode" value="both"/>-->


            <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
            <property name="javax.persistence.schema-generation.create-source" value="metadata"/>
            <property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
            <!--<property name="javax.persistence.sql-load-script-source" value="META-INF/load.sql"/>-->
        </properties>
    </persistence-unit>
</persistence>

I have logged in to the glassfish 5 console from localhost:4848 and configured a connection pool and a jdbc resource there. I suspect this is where I have done something wrong, so I will include screenshots of it just to make sure.

Connection pool: Connection pool Connection pool additional fields

Resource pool Resource pool details

I really have no idea how to fix this. Here is the exception log (i cannot enter more than 30k characters for the whole server log)

[2018-11-07T16:48:22.825+0200] [Payara 5.183] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=50 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1541602102825] [levelValue: 1000] [[
  Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: Invalid resource : mitblick__pm
    at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:182)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:978)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepare(ApplicationLifecycle.java:438)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:540)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:549)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:545)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:544)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:575)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:567)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:566)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1475)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:111)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1857)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1733)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:564)
    at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:251)
    at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:166)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:516)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:213)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Invalid resource : mitblick__pm
    at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:593)
    at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:517)
    at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
    at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
    at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:150)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:114)
    at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:225)
    at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:525)
    at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:240)
    at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:170)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:978)
    at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:309)
    at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:88)
    at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:155)
    at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:152)
    at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:232)
    at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:241)
    at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:270)
    at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:152)
    ... 39 more
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : mitblick__pm
    at org.glassfish.jdbcruntime.service.JdbcDataSource.validateResource(JdbcDataSource.java:82)
    at org.glassfish.jdbcruntime.service.JdbcDataSource.setResourceInfo(JdbcDataSource.java:63)
    at org.glassfish.jdbcruntime.JdbcRuntimeExtension.lookupDataSourceInDAS(JdbcRuntimeExtension.java:142)
    at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:589)
    ... 58 more
]]

Answer:

So I managed to figure it out by breaking a manifest file, the server just dumped part of the error it was actually getting and it turns out that I had a typo in a string constant representing a jpql query. (usr instead of user)

Question:

I am attempting to read a Timestamp value from a postgres database. I have tried various mappings, at the moment I am using the following mapping:

@Column(name = "Anlagedatum")
private Timestamp anlagedatum;

If I query the database using SQL, I get, for the first date 2015-02-27.

If I execute the JPA code using a scratch.java on my local machine, I get 2015-02-27

When the exact same query executes in the context of MY LOCAL Payara server, I get an incorrect date. The really wierd part is that my timezone is GMT +2, not +1.

The date returned by payara server is 2015-02-26 23:00:00

Why would payara server JPA change the date? How do I change the mapping so that it gets the date stored without manipulation?


Answer:

This look like a problem with the daylight saving time in your timezone.

First thing to check is which column type you are using in your Postgresql Database. You should use: 'timestamp with timezone';

If this is already the case you can try the following:

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
@Column(name = "Anlagedatum")
private Timestamp anlagedatum;

If this doesn't help, I would try it with the 'Date' type in Java:

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
@Column(name = "Anlagedatum")
private Date anlagedatum;

Question:

I have a j2ee app running but i decided to change the code organization to a package by feature style instead of the package by layer style that i am using now, the main reasons for this change are code navigation and modulatity, i have this schema:

  • com.app.domain
    • customer.java
  • com.app.dao
    • customerDao.java
    • customerDaoImpl.java
  • com.app.service
    • customerService.java
    • customerServiceImpl.java
  • com.app.web
    • customerHandler.java

I want to move it to:

  • com.app.customer
    • customer.java
    • customerDao.java
    • customerDaoImpl.java
    • customerService.java
    • customerServiceImpl.java
    • customerHandler.java

When i run tests on the new schema everything works fine but when a try to use the customerService via the customerHandler i get this error:

No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call

I tried grouping my classes into the new package one by one to see wich one is the problem, and it is the customerServiceImpl.java, when i move this class outside the com.app.customer package my app works fine, the applicationContext.xml file is configured to scan the com.app.customer package, the customerDaoImpl and customerServiceImpl have @Transactional annotations, i read that either the dao or the service should be transactional but not both, so i tried removing this annotation from either class but i still get the same error.

This is the full stack trace:

Warning: StandardWrapperValve[dispatcher]: Servlet.service() for servlet dispatcher threw exception    
javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
        at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:278)
        at com.sun.proxy.$Proxy234.merge(Unknown Source)
        at com.app.customer.customerDaoImpl.merge(customerDaoImpl.java:49)
        at com.app.customer.customerServiceImpl.store(customerServiceImpl.java:69)
        at com.app.customer.customerHandler.store(customerHandler.java:39)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
        at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
        at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
        at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
        at java.lang.Thread.run(Thread.java:745)

What am i doing wrong? is it possible to build an app using the package by feature style with eclipselink JPA?

By the way i am able to retrieve customer info from the database.

EDIT:

This is the applicationContext.xml file with the orginal packaging style:

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.2.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    <bean id="loadTimeWeaver"  class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver" />
    <bean id="entityManagerFactory" p:persistenceUnitName="app_PU"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
    />
    <tx:jta-transaction-manager />
    <tx:annotation-driven />
    <context:annotation-config/> 
    <context:component-scan base-package="com.app.dao"/>
    <context:component-scan base-package="com.app.service"/>
</beans>

For the new packaging style i changed this:

<context:component-scan base-package="com.app.dao"/>
<context:component-scan base-package="com.app.service"/>

To this:

<context:component-scan base-package="com.app.customer"/>

Then i get the error mentioned above, but if i move the customerServiceImpl.class outside the package com.app.customer to its original location: com.app.service and change the applicationContext.xml to:

<context:component-scan base-package="com.app.customer"/>
<context:component-scan base-package="com.app.service"/>

My app works.

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="app_PU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/appDB</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="eclipselink.target-server" value="SunAS9"/>
            <property name="eclipselink.logging.level" value="INFO"/>
        </properties>
    </persistence-unit>
</persistence>

Answer:

It turns out that when the Controller, Service and DAO classes are in the same package any method call made from the Controller object to the Service object is considered by Spring as a self-invocation call, that's why no transactional behavior was added to the persist, merge or remove methods, it also explains why the app worked when moving either the ServiceImpl or the DaoImpl class to a different package, because thay way any method call is considered as an external call and will be intercepted by the proxy.

The problem was solved by changing the transactional mode to AOP, this link was useful for configuring the new transactional mode.

Question:

I'm trying to walk through the JPA-RS tutorials like: http://java.dzone.com/articles/introducing-eclipselink-jpa-rs or http://www.eclipse.org/eclipselink/documentation/2.5/solutions/restful_jpa.htm

But after trying to deploy (using the maven and glassfish plugin) the application on my glassfish I get the following error stacktrace:

WebModule[/rest]Servlet /rest threw load() exception java.lang.ClassNotFoundException: 
org.eclipse.persistence.jpa.rs.resources.MetadataResource at 
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1783) at
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633
) at org.eclipse.persistence.jpa.rs.service.JPARSApplication.(JPARSApplication.java:62) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at 
...

I do not find the class in my imported dependencies:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpars</artifactId>
    <version>2.6.0</version>
</dependency>

By searching for that error, I getting no one who is sharing the same problem with me. Are you able to help me by getting an solution for that problem? Tell me if you need more conext/background information about the project.

Kind regards.


Answer:

Use your eclipselink dependencies of the same version: either both eclipselink and org.eclipse.persistence.jpars should be 2.6.0 or both should be 2.5.0.

When using 2.6.0 org.eclipse.persistence.jpa.rs.resources.MetadataResource is in the eclipselink.jar