春季批量工作|嵌套异常是org.hibernate.exception.GenericJDBCException:无法执行语句|当前交易中止

时间:2018-05-14 12:30:17

标签: java postgresql hibernate spring-batch transactional

我有一张表ReservationDataHash。相同的实体是:

ReservationDataHash.java:

set_error_handler('fatalErrorHandler', [E_ERROR]);

function fatalErrorHandler($errno, $errstr, $errfile, $errline){
     throw new \Exception($errstr." @$errfile:$errline", $errno);
}

/* ... */ 

try{
     // Likely defective code...
}catch(\Exception $e) {
     $cronlocklog->add("cron job failed with error: ".$e->getMessage());
} finally {
     flock($cronlockfd, LOCK_UN);
}

存储库是,

GuestHashCodeRepository.java

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

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

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

/**
 * The Class GuestHashCode.
 */
@Entity
@Table(name = "reservationdatahash", schema = "public")
public class ReservationDataHash implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;

/** The entity hash id. */
@Id
@GenericGenerator(name = "uuid", strategy = "uuid2")
@GeneratedValue(generator = "uuid")
@Column(name = "reservationdatahashid", unique = true, nullable = false)
@Type(type = "pg-uuid")
private UUID hashId;

/** The entity code. */
@Column(name = "uniquesourceid")
private String uniqueSourceId;

/** The dxp id. */
@Column(name = "dxpid")
private String dxpId;

/** The hash code. */
@Column(name = "hashcode")
private String hashCode;

/** The failed hash code. */
@Column(name = "failedhashcode")
private String failedHashCode;

/** The retry attempt. */
@Column(name = "retrycount")
private Integer retryAttempt;

/** The last modified date. */
@NotNull
@Column(name = "lastmodifieddate")
private Date lastModifiedDate;


public UUID getHashId() {
    return hashId;
}

public void setHashId(UUID hashId) {
    this.hashId = hashId;
}

public String getUniqueSourceId() {
    return uniqueSourceId;
}

public void setUniqueSourceId(String uniqueSourceId) {
    this.uniqueSourceId = uniqueSourceId;
}

/**
 * Gets the dxp id.
 *
 * @return the dxp id
 */
public final String getDxpId() {
    return dxpId;
}

/**
 * Sets the dxp id.
 *
 * @param dxpId
 *            the new dxp id
 */
public final void setDxpId(final String dxpId) {
    this.dxpId = dxpId;
}

/**
 * Gets the hash code.
 *
 * @return the hash code
 */
public final String getHashCode() {
    return hashCode;
}

/**
 * Sets the hash code.
 *
 * @param hashCode
 *            the new hash code
 */
public final void setHashCode(final String hashCode) {
    this.hashCode = hashCode;
}

/**
 * Gets the failed hash code.
 *
 * @return the failed hash code
 */
public final String getFailedHashCode() {
    return failedHashCode;
}

/**
 * Sets the failed hash code.
 *
 * @param failedHashCode
 *            the new failed hash code
 */
public final void setFailedHashCode(final String failedHashCode) {
    this.failedHashCode = failedHashCode;
}

/**
 * Gets the retry attempt.
 *
 * @return the retry attempt
 */
public final Integer getRetryAttempt() {
    return retryAttempt;
}

/**
 * Sets the retry attempt.
 *
 * @param retryAttempt
 *            the new retry attempt
 */
public final void setRetryAttempt(final Integer retryAttempt) {
    this.retryAttempt = retryAttempt;
}

/**
 * Gets the last modified date.
 *
 * @return the last modified date
 */
public final Date getLastModifiedDate() {
    return lastModifiedDate;
}

/**
 * Sets the last modified date.
 *
 * @param lastModifiedDate
 *            the new last modified date
 */
public final void setLastModifiedDate(final Date lastModifiedDate) {
    this.lastModifiedDate = lastModifiedDate;
}

}

我经常在我的Processor()中调用方法import java.util.UUID; import javax.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; /** * The Interface EntityHashRepository. */ @Repository @Transactional public interface GuestHashCodeRepository extends JpaRepository<ReservationDataHash, UUID> { @Query("select r from ReservationDataHash r " + "where (r.uniqueSourceId = :uniqueSourceId) ") ReservationDataHash findByUniqueSourceId( @Param("uniqueSourceId") String uniqueSourceId ); }

findByUniqueSourceId()

一段时间后,当批处理作业在环境中运行时,我开始在服务中看到此方法中传递的所有数据的以下错误,

public ReservationDataHash getReservationGuestHashCodeByUniqueSourceId(String uniqueSourceID) {

    return guestHashCodeRepo.findByUniqueSourceId(uniqueSourceID);
}

当我为本地连接到同一数据库的特定数据测试相同内容时,我不会遇到任何错误。

请帮助我,因为我无法理解这个问题。

1 个答案:

答案 0 :(得分:0)

看起来你的堆栈跟踪很低,你的交易中止了 - 我猜你的交易会因为死锁而被取消?

其他人可能只是锁定了您要读取的行,最终导致死锁。

也许你可以通过不使用交易来逃脱它? (假设这些ID不会改变)否则,您可能需要在较高级别重新启动事务。