구문 오류가 발생하거나 주문""테이블을 하는 동안 간단한 선택[중복]

0

질문

좋은 하루,지역 사회!

문제:

내가 노력하고 단순히 주문에서 DB 를 사용하여 SpringData 고 CrudRepository<Order, Long>지만,받은 다음에 오류가 있습니다:

2021-11-22 12:34:27.787  WARN 3119 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42601
2021-11-22 12:34:27.788 ERROR 3119 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: syntax error at or near "order"
  Position: 1136

다른 엔터티를 같은 사용자,계약 또는 생산자가 가져오는 일반적으로. 또한 나도 가지 않고,순서 OrderProduct 하지만 오류가 있습니다.더 보기

체:

OrderEntity

@Entity
@Table(name = "order")
public class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long  id;
    public Long   getId() { return id; }

    @ManyToOne
    @JoinColumn(name = "creator_id")
    private User creator;
    public User  getCreator() { return creator; }
    public void  setCreator(final User creator) { this.creator = creator; }

    @ManyToOne
    @JoinColumn(name = "contract_id")
    private Contract contract;
    public Contract  getContract() { return contract; }
    public void      setContract(final Contract contract) { this.contract = contract; }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "order")
    private List<OrderProduct> orderProducts;
    public void                setOrderProducts(final List<OrderProduct> orderProducts) { this.orderProducts = orderProducts; }
    public List<OrderProduct>  getOrderProducts() { return orderProducts; }

    private Date arrivingDate;
    public void  setArrivingDate(final Date arrivingDate) { this.arrivingDate = arrivingDate; }
    public Date  getArrivingDate() { return arrivingDate; }

    @Enumerated(EnumType.STRING)

    private Status status;
    public void    setStatus(final Status status) { this.status = status; }
    public Status  getStatus() { return status; }

    private Date creationDate;
    public void  setCreationDate(final Date creationDate) { this.creationDate = creationDate; }
    public Date  getCreationDate() { return creationDate; }

    private String document;
    public void    setDocument(final String document) { this.document = document; }
    public String  getDocument() { return document; }


    protected Order() {}
    public Order(User creator, Contract contract, List<OrderProduct> orderProducts, Date arrivingDate, String document, Status status, Date creationDate) {
        this.creator       = creator;
        this.contract      = contract;
        this.arrivingDate  = arrivingDate;
        this.status        = status;
        this.creationDate  = creationDate;
        this.document      = document;
        this.orderProducts = orderProducts;
    }
}

OrderProductEntity

@Entity
@Table(name = "order_product")
public class OrderProduct {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long  id;
    public Long   getId() { return id; }

    @ManyToOne
    @JoinColumn(name = "product_id")
    private Product product;
    public Product  getProduct() { return product; }
    public void     setProduct(final Product product) { this.product = product; }

    @ManyToOne
    @JoinColumn(name = "order_id")
    private Order order;
    public Order  getOrder() { return order; }
    public void   setOrder(final Order order) { this.order = order; }

    private Integer quantity;
    public void setQuantity(final Integer quantity) { this.quantity = quantity; }
    public Integer getQuantity() { return quantity; }


    protected OrderProduct() {}
    public OrderProduct(final Product product, final Order order, final Integer quantity) {
        this.product  = product;
        this.order    = order;
        this.quantity = quantity;
    }
}

가져오는 코드

@Override
public Order findById(final Long id) throws Exception {
    return orderRepository.findById(id)
        .orElseThrow(() -> new Exception("There is no order by id:" + id));
}

최대 절전 모드십시오.디버그:

select
        order0_.id as id1_2_0_,
        order0_.arriving_date as arriving2_2_0_,
        order0_.contract_id as contract6_2_0_,
        order0_.creation_date as creation3_2_0_,
        order0_.creator_id as creator_7_2_0_,
        order0_.document as document4_2_0_,
        order0_.status as status5_2_0_,
        contract1_.id as id1_1_1_,
        contract1_.creator_id as creator_4_1_1_,
        contract1_.end_date as end_date2_1_1_,
        contract1_.producer_id as producer5_1_1_,
        contract1_.start_date as start_da3_1_1_,
        user2_.id as id1_0_2_,
        user2_.email as email2_0_2_,
        user2_.name as name3_0_2_,
        user2_.password as password4_0_2_,
        user2_.phone as phone5_0_2_,
        user2_.position as position6_0_2_,
        user2_.surname as surname7_0_2_,
        producer3_.id as id1_4_3_,
        producer3_.city as city2_4_3_,
        producer3_.contact_email as contact_3_4_3_,
        producer3_.contact_name as contact_4_4_3_,
        producer3_.contact_phone as contact_5_4_3_,
        producer3_.country as country6_4_3_,
        producer3_.street as street7_4_3_,
        user4_.id as id1_0_4_,
        user4_.email as email2_0_4_,
        user4_.name as name3_0_4_,
        user4_.password as password4_0_4_,
        user4_.phone as phone5_0_4_,
        user4_.position as position6_0_4_,
        user4_.surname as surname7_0_4_
    from

    order order0_ left outer join
        contract contract1_
            on order0_.contract_id=contract1_.id
    left outer join
        client user2_
            on contract1_.creator_id=user2_.id
    left outer join
        producer producer3_
            on contract1_.producer_id=producer3_.id
    left outer join
        client user4_
            on order0_.creator_id=user4_.id
    where
        order0_.id=?

DB 다이어그램:

다이어그램

감사에 대한 당신의 시간과 관심!

hibernate java postgresql spring
2021-11-22 11:23:30
1

최고의 응답

-2

이후 주문 예약어에서 SQL,해야 합니다 나는 그것을 당신의 이름을 추가하여 테이블 backticks 처럼`. 를 추가하는 대신 귀하의 엔티티가 이:

@Table(name = "order") 

Add this:

@Table(name = "`order`")

여기에서,단어 order 안에 들어 backticks.

2021-11-22 11:31:34

Backticks? Double quotes"you mean. 도 MySQL 지원 double quotes.
Frank Heikens

그것은 backticks,나는 또한 테이블 라는 순서와는 방법에 액세스 mySQL.
njari

아니,그것은,그것을 시도하는 모든 데이터베이스에서,그리고 그만 작품에서 MySQL. PostgreSQL,SQL Server Oracle,그들은 받아들이지 않 backticks.
Frank Heikens

도 큰 따옴표,작동하지 않았습니다. 나 MariaDB.
njari

Backticks 을 인용하는 키워드는 잘못된서 Postgres 및 표준 SQL.
a_horse_with_no_name

체크의 일 때 이스케이프 mariadb.com/kb/en/sql-mode/#ansi_quotes 을 강제로 들여오기/내보내기 플러그인이 사용하는 표준 SQL 기능이 있습니다.
Frank Heikens

감사,몰랐던 이지 않는 표준 SQL! 뭔가 새로운 일상이다.
njari

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................