Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将事务Springboot提交到Mysql_Java_Mysql_Spring_Spring Boot_Mysql Workbench - Fatal编程技术网

Java 无法将事务Springboot提交到Mysql

Java 无法将事务Springboot提交到Mysql,java,mysql,spring,spring-boot,mysql-workbench,Java,Mysql,Spring,Spring Boot,Mysql Workbench,我做了一个这样的项目:并且正常运行 但当我在MYSQL中用列(name=“id”)更改“id”时。我在邮递员身上做测试时出错了 { "timestamp": 1533183310810, "status": 500, "error": "Internal Server Error", "exception": "org.springframework.transaction.UnexpectedRollbackException", "message": "JTA transaction une

我做了一个这样的项目:并且正常运行

但当我在MYSQL中用列(name=“id”)更改“id”时。我在邮递员身上做测试时出错了

{
"timestamp": 1533183310810,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.transaction.UnexpectedRollbackException",
"message": "JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction.",
"path": "/save"
}
我更改了某个类别的客户:

@Id
@Column(name="id")
private long id;

public Customer(long id , String firstName, String lastName){
    this.id=id;
    this.firstName=firstName;
    this.lastName=lastName;
}
在WebController类中,我使用id、名字和姓氏保存客户

@RequestMapping("/save")
public String process(){
    repository.save(new Customer(1,"Jack", "Smith"));
    return "Done";
}

如何使用id保存客户

在那篇文章中,他们对Id列使用了
GenerationType.AUTO
策略。这意味着ID列中的值将自动生成。因此,要保存记录,不需要显式提供ID

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
保存应如下所示:

repository.save(new Customer("Jack", "Smith"));

这样做的好处是,您无需关心您要分配的ID是否已分配给任何其他记录。JPA负责为所有新记录分配一个新ID。

您可能会遇到此错误,因为您试图插入的ID可能已经在数据库中。如果您尝试插入具有不同id的数据,您的代码将起作用


尽管我们通常遵循上面共享的方法(@GeneratedValue(strategy=GenerationType.AUTO))。

在调试时,我看到错误:“ARJUNA016060:TransactionImple.enstresource-capture:XAException.XAER_INVAL”ConnectionImple.registerDatabase-ARJUNA017017:资源登记失败,ARJUNA012125:TwoPhaseCoordinator.Before Completion-同步失败Imple<0:ffffac10043e:cfd4:5b628ab4:18,org.hibernate.resource.transaction.backend.jta.internal.synchronization。RegisteredSynchronization@3899e7d6>请将stacktrace添加到您的问题中。请这样做。我想如果在数据库中,如果我有6行id为1-6,并且我删除了id=1的行。当我插入数据库时,如果我使用@GeneratedValue,现在的id是7,但我希望id=1。这就是我问这个问题的原因。请在你的问题顶部提到这个。我知道这一点。我想如果在数据库中,如果我有6行id为1-6,并且我删除了id=1的行。当我插入数据库时,如果我使用@GeneratedValue,现在的id是7,但我希望id=1。这就是为什么我要问这个问题。ID不在我的数据库中,但当我从Spring boot插入时。我有错误。。。。