0

I want to set up an application running on GlassFish 4.1.1 with EclipseLink and Spring. My database is PostgreSQL. Below is my configuration. When I try to invoke /facebookDebug method I get "javax.transaction.RollbackException: Transaction marked for rollback" which is not very descriptive. Please look at my configuration. Is there everything ok? I can add a log from the server start, maybe you will find something there.

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
    <persistence-unit name="amleto-server-model" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>amleto-server-model</jta-data-source>
    <class>com.amleto.server.model.entities.FacebookDebug</class>
    <properties>
        <property name="eclipselink.logging.level" value="ALL" />
        <property name="eclipselink.logging.level.sql" value="ALL"/>
        <property name="eclipselink.logging.parameters" value="true" />
        <property name="eclipselink.logging.connection" value="true" />
        <property name="eclipselink.logging.session" value="true" />
        <property name="eclipselink.logging.thread" value="true" />
        <property name="eclipselink.logging.timestamp" value="true" />
        <property name="eclipselink.target-database" value="PostgreSQL" />
    </properties>
</persistence-unit>

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

<context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true" />

<context:annotation-config />
<!--  controllers -->
<mvc:annotation-driven />

<context:component-scan base-package="com.amleto.server.model.entities" />
<context:component-scan base-package="com.amleto.server.services.controllers" />

<jpa:repositories base-package="com.amleto.server.model.repositories"/>

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="amleto-server-model"/>
</bean>

<tx:jta-transaction-manager />
<tx:annotation-driven/>

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
</beans>

FacebookDebug.java

package com.amleto.server.model.entities;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;

@Entity
@Table(name="facebook_debug")
@NamedQuery(name="FacebookDebug.findAll", query="SELECT f FROM FacebookDebug f")
public class FacebookDebug implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="facebook_debug_id")
private Integer facebookDebugId;

@Column(name="app_action")
private String appAction;

@Column(name="date_create")
private Timestamp dateCreate;

@Column(name="user_id")
private String userId;

public FacebookDebug() {
}

public Integer getFacebookDebugId() {
    return this.facebookDebugId;
}

public void setFacebookDebugId(Integer facebookDebugId) {
    this.facebookDebugId = facebookDebugId;
}

public String getAppAction() {
    return this.appAction;
}

public void setAppAction(String appAction) {
    this.appAction = appAction;
}

public Timestamp getDateCreate() {
    return this.dateCreate;
}

public void setDateCreate(Timestamp dateCreate) {
    this.dateCreate = dateCreate;
}

public String getUserId() {
    return this.userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

}

FacebookDebugRepository.java

package com.amleto.server.model.repositories;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.amleto.server.model.entities.FacebookDebug;

@Repository
public interface FacebookDebugRepository extends CrudRepository<FacebookDebug, Integer> {

}

AmletoController.java

package com.amleto.server.services.controllers;

import java.sql.Timestamp;
import java.util.GregorianCalendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.amleto.server.model.entities.FacebookDebug;
import com.amleto.server.model.repositories.FacebookDebugRepository;

@Controller
public class AmletoController {

@Autowired
FacebookDebugRepository repo;

@Transactional
@ResponseBody
@RequestMapping(value = "/facebookDebug", method=RequestMethod.GET)
public String facebookDebug(@RequestParam(value="action", required=true) String action, 
                            @RequestParam(value="userId", required=true) String userId) {
    String returnValue = "";

    FacebookDebug fb = new FacebookDebug();
    fb.setAppAction(action);
    fb.setUserId(userId);
    GregorianCalendar dateCreate = new GregorianCalendar();
    fb.setDateCreate(new Timestamp(dateCreate.getTimeInMillis()));

    repo.save(fb);

    return "Grazie.";
}

}

stacktrace:

[2015-11-08T17:33:46.604+0100] [glassfish 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=29 _ThreadName=http-listener-1(4)] [timeMillis: 1447000426604] [levelValue: 900] [[ StandardWrapperValve[spring-dispatcher]: Servlet.service() for servlet spring-dispatcher threw exception javax.transaction.RollbackException: Transaction marked for rollback. at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:445) at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:854) at com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:212) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1021) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:119) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy229.save(Unknown Source) at com.amleto.server.services.controllers.amletoController.facebookDebug(amletoController.java:58) 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:601) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729) 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:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) 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:722) ]]

Jacek
  • 187
  • 2
  • 13
  • All this shows is that there was an error and the transaction was marked for rollback. Check your application code to make sure you aren't catching and ignoring an exception that would cause the transaction to be marked or rollback, and then allowing the transaction to attempt to commit. You will need to check the logs to find out what was occurring leading up to the error as well. – Chris Nov 09 '15 at 13:35
  • There are no try/catch blocks. You see all the code there is. Here you can see the log file from the server start: https://www.dropbox.com/s/ks9q4bneyijigeq/serverstart.log?dl=0 . Please take a look. There is an EclipseLink warning about some exception, but from what I found in the web it is not that relevant - maybe I'm wrong? – Jacek Nov 09 '15 at 16:35
  • I assume you have looked at http://stackoverflow.com/questions/32142789/nullpointer-in-log-during-first-connection-to-database for the NPE in the logs and is likely where you found the target-database idea. Your situation is very different though, as deploying a persistence unit with a JTA transaction-type requires that EclipseLink be able have a server platform class to look up the external transaction controller class, in order to associate with the active transaction. You are also deploying on WLS, so the server should have been detected - this is likely an issue with the spring config. – Chris Nov 09 '15 at 19:43
  • Thing is that with the EXACT SAME context.xml and OpenJPA the app works fine (saving to database works like a charm). Of course the persistence.xml file is a little different, an OpenJPA enhancer instead of EclipseLink enhancer is used and slightly different libs. I think I'll stick with OpenJPA because I can't get EclipseLink to work for a week. Looks like it's pretty buggy. – Jacek Nov 09 '15 at 21:40
  • Spring does different things to the contexts and might be where the problem lies. Or not. If it is working in OpenJPA, try setting the target-server to WebLogic, as it could just be the JTA hook up is missing and not being set through your Spring configuration. Your exception is missing a cause as well though, which makes it difficult to guess what is happening. – Chris Nov 10 '15 at 14:24

1 Answers1

-1

I have found a solution (which leads me to another error, but it is a step forward).

It turned out that I had to change target-database value to "Database". There is a known EclipseLink bug which throws an exception unless the value of the parameter is equal to "Database". Now I have another problem which can be found here.

Community
  • 1
  • 1
Jacek
  • 187
  • 2
  • 13