GenerationTarget遇到异常接受命令:执行DDL“创建表时出错

时间:2019-02-03 11:47:01

标签: java hibernate jpa jakarta-ee

我是Java EE的新手,我正在尝试实现Hibernate JPA关系,但是发生的情况之一是未创建付款表,但引发了下面的错误,但是联接表存在:

GenerationTarget encountered exception accepting command : Error executing DDL "create table payments (reference varchar(255) not null, Status Pending, ThirdPartyReference varchar(255) not null, amount double precision not null, dateCompleted date, dateCreated date not null, description varchar(255), dueDate date, payer_PhoneNumber varchar(12) not null, specialReference varchar(14) not null, acctount_id bigint, primary key (reference)) engine=InnoDB" via JDBC Statement
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL 

以下是付款类别的详细信息:

package Organization.Core.Gateway.entities;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;

@Entity (name= "payments")
public class Payment {

    public Account getServiceProvider() {
        return ServiceProvider;
    }

    public void setServiceProvider(Account serviceProvider) {
        ServiceProvider = serviceProvider;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String getThirdPartyReference() {
        return ThirdPartyReference;
    }

    public void setThirdPartyReference(String thirdPartyReference) {
        ThirdPartyReference = thirdPartyReference;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSpecialReference() {
        return specialReference;
    }

    public void setSpecialReference(String specialReference) {
        this.specialReference = specialReference;
    }

    public String getStatus() {
        return Status;
    }

    public void setStatus(String status) {
        Status = status;
    }

    public String getPayer_PhoneNumber() {
        return payer_PhoneNumber;
    }

    public void setPayer_PhoneNumber(String MSISDN) {
        this.payer_PhoneNumber = MSISDN;
    }

    public LocalDate getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(LocalDate dateCreated) {
        this.dateCreated = dateCreated;
    }

    public LocalDate getDateCompleted() {
        return dateCompleted;
    }

    public void setDateCompleted(LocalDate dateCompleted) {
        this.dateCompleted = dateCompleted;
    }

    public LocalDate getDueDate() {
        return dueDate;
    }

    public void setDueDate(LocalDate dueDate) {
        this.dueDate = dueDate;
    }

    @OneToOne(targetEntity = Account.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "acctount_id", referencedColumnName = "Id")
    private  Account ServiceProvider;

    private  double amount;

    @Column(unique = true, nullable = false)
    private  String ThirdPartyReference;

    @Id
    //@GeneratedValue(strategy = GenerationType.AUTO)
    //@SequenceGenerator(name = "reference_generator", sequenceName = "PAY", allocationSize = 15)
    private String reference;

    private String description;

    @Column(nullable = false, length = 14)
    private String specialReference;

    @Column(columnDefinition = "Pending")
    private String Status;


    @Column(nullable = false,length =12)
    private  String payer_PhoneNumber;

    @Column(nullable = false)
    private LocalDate dateCreated;


    private  LocalDate dateCompleted;

    private  LocalDate dueDate;
}

比帐户详细信息

package Organization.Core.Gateway.entities;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Set;

@Entity( name = "accounts")
@Inheritance(strategy = InheritanceType.JOINED)
public class Account {

    @Override
    public String toString() {
        return "Account{" +
                "Id=" + Id +
                ", FirstName='" + FirstName + '\'' +
                ", Surname='" + Surname + '\'' +
                ", Payments=" + Payments +
                '}';
    }

    public Long getId() {
        return Id;
    }

    public void setId(Long id) {
        Id = id;
    }

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String firstName) {
        FirstName = firstName;
    }

    public String getSurname() {
        return Surname;
    }

    public void setSurname(String surname) {
        Surname = surname;
    }

    public Set<Payment> getPayments() {
        return Payments;
    }

    public void setPayments(Set<Payment> payments) {
        Payments = payments;
    }

    @javax.persistence.Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private  Long Id;

    @NotNull
    private  String FirstName;

    @NotNull
    private  String Surname;

    @OneToMany(targetEntity = Payment.class, fetch = FetchType.LAZY)
    private Set<Payment> Payments;



}

最后是我要访问的商家帐户:

package Organization.Core.Gateway.entities;
import javax.persistence.Column;
import javax.persistence.Entity;

@Entity(name = "merchants")
public class Merchant  extends  Account{

    public int getMpesa_ServiceproviderCode() {
        return mpesa_ServiceproviderCode;
    }

    public void setMpesa_ServiceproviderCode(int mpesa_ServiceproviderCode) {
        this.mpesa_ServiceproviderCode = mpesa_ServiceproviderCode;
    }

    public String getOrganizationName() {
        return organizationName;
    }

    public void setOrganizationName(String organizationName) {
        this.organizationName = organizationName;
    }

    @Column(name = "providershortCode")
    private int mpesa_ServiceproviderCode;

    @Override
    public String toString() {
        return "Merchant{" +
                "mpesa_ServiceproviderCode=" + mpesa_ServiceproviderCode +
                ", organizationName='" + organizationName + '\'' +
                '}';
    }

    private String organizationName;
}

持久性文件详细信息

<?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="molapayPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/organization" />
            <property name="javax.persistence.jdbc.user" value="organization" />
            <property name="javax.persistence.jdbc.password" value="_P4ym3nt01" />
            <!--Hibernate Configuration -->
            <!-- dialect for MySQL-->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect" />
             <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.flushMode" value="FLUSH_AUTO" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />

            <!-- POOL -->
            <property name="hibernate.c3p0.min_size" value="5"/>
            <property name="hibernate.c3p0.max_size" value="20"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="3000"/>
        </properties>
    </persistence-unit>
</persistence>

PS:我读了一些我试图更改方言的文章,因为我使用的是mariadb,并且甚至评论了here上的文章。

0 个答案:

没有答案