सिंटैक्स त्रुटि या "आदेश" मेज कर रही है, जबकि सरल का चयन करें [नकल]

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));
}

हाइबरनेट PSQL डिबग:

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=?

डीबी आरेख:

आरेख

के लिए धन्यवाद अपने समय और ध्यान!

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

सबसे अच्छा जवाब

-2

के आदेश के बाद से एक आरक्षित शब्द है SQL में है, तो आप चाहिए संकेत मिलता है कि यह नाम आपके द्वारा तालिका जोड़ने backticks `की तरह. जोड़ने के बजाय अपनी इकाई इस तरह से :

@Table(name = "order") 

इस जोड़ें :

@Table(name = "`order`")

यहाँ, शब्द order है के भीतर संलग्न backticks.

2021-11-22 11:31:34

Backticks? डबल उद्धरण " आप का मतलब है. यहां तक कि MySQL का समर्थन करता है, डबल उद्धरण.
Frank Heikens

यह backticks, मैं भी एक तालिका नाम के क्रम और कहा कि यह कैसे पर पहुँचा mySQL.
njari

नहीं, यह नहीं है, यह देने की कोशिश में किसी भी डेटाबेस, और है कि केवल काम करता है MySQL में. पोस्टग्रे-एसक्यूएल, SQL सर्वर, ओरेकल, वे स्वीकार नहीं करते backticks.
Frank Heikens

की कोशिश की डबल उद्धरण, मेरे लिए काम नहीं किया. मैं कर रहा हूँ पर MariaDB.
njari

Backticks बोली के लिए कीवर्ड अमान्य कर रहे हैं में Postgres और मानक SQL.
a_horse_with_no_name

की जाँच करें ANSI_QUOTES mariadb.com/kb/en/sql-mode/#ansi_quotes मजबूर करने के लिए MySQL/MariaDB का उपयोग करने के लिए मानक SQL कार्यक्षमता ।
Frank Heikens

धन्यवाद, यह पता नहीं था नहीं था मानक SQL! कुछ नया हर रोज.
njari

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में