本文介绍了GlassFish 4.1.1 Spring 4.0.9,EclipseLink,PostgreSQL - 事务标记为回滚,没有任何信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用EclipseLink和Spring设置在GlassFish 4.1.1上运行的应用程序。我的数据库是PostgreSQL。以下是我的配置。当我尝试调用/ facebookDebug方法时,我得到javax.transaction.RollbackException:标记为回滚的事务,这不是非常具有描述性。请看我的配置。有没有好的?我可以从服务器开始添加一个日志,也许你会发现一些东西。



persistence.xml

 <?xml version =1.0encoding =UTF-8?> 
< persistence version =2.0xmlns =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-modeltransaction-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>
<属性>
< property name =eclipselink.logging.levelvalue =ALL/>
< property name =eclipselink.logging.level.sqlvalue =ALL/>
< property name =eclipselink.logging.parametersvalue =true/>
< property name =eclipselink.logging.connectionvalue =true/>
< property name =eclipselink.logging.sessionvalue =true/>
< property name =eclipselink.logging.threadvalue =true/>
< property name =eclipselink.logging.timestampvalue =true/>
< property name =eclipselink.target-databasevalue =PostgreSQL/>
< / properties>
< / persistence-unit>


context.xml

 <?xml version =1.0encoding =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/弹簧jpa.xsd>

< context:property-placeholder location =classpath:config.propertiesignore-unresolvable =true/>

< context:annotation-config />
< 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 =entityManagerFactoryclass =org.springframework.orm.jpa.LocalEntityManagerFactoryBean>
< property name =persistenceUnitNamevalue =amleto-server-model/>
< / bean>

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

< bean id =transactionManagerclass =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实现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)
私人时间戳记dateCreate;

@Column(name =user_id)
private String userId;
$ b $ 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;


$ b code
$ b

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扩展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);

返回Grazie。;
}

}

stacktrace:


解决方案

我找到了一个解决方案(这导致我出现另一个错误,但它向​​前迈进了一步)。

事实证明,我必须将目标数据库值更改为数据库。有一个已知的EclipseLink错误会引发异常,除非参数的值等于数据库。现在我遇到了另一个问题,可以在这里找到。


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:

解决方案

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.

这篇关于GlassFish 4.1.1 Spring 4.0.9,EclipseLink,PostgreSQL - 事务标记为回滚,没有任何信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 20:58