当前位置: 首页 > 知识库问答 >
问题:

ORA-00904:"BOOKORDERS": Hibernate中的无效标识符

燕经国
2023-03-14

我在将订单信息插入oracle数据库时遇到了问题。当我在JUnit类中调用createOrder funtion时,它会抛出如下所示的错误。

Hibernate: select ORDERS_SEQ.nextval from dual
Hibernate: insert into BOOKORDERS (CUSTOMER_ID, ORDER_DATE, ORDER_STATUS, 
ORDER_TOTAL, PAYMENT_METHOD, RECIPIENT_NAME, RECIPIENT_PHONE, 
SHIPPING_ADDRESS, ORDER_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into DETAILORDER (quantity, subTotal, book, bookorders) 
values (?, ?, ?, ?)
May 22, 2019 12:26:18 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper 
logExceptions
WARN: SQL Error: 904, SQLState: 42000
May 22, 2019 12:26:18 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper 
logExceptions
ERROR: ORA-00904: "BOOKORDERS": invalid identifier

我该怎么修?

我可以在实体包中与其相关类共享相关代码订单类。

图书订购类

    @Entity
    @Table(name="BOOKORDERS",catalog = "JSPPROJECTDATABASE")
    public class BookOrders implements Serializable{
    ...

    @Id
    @SequenceGenerator(name="ORDERS_SEQ", sequenceName="ORDERS_SEQ", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ORDERS_SEQ")
    @Column(name="ORDER_ID", nullable = false)
    private int id;

    @OneToMany(fetch = FetchType.EAGER,mappedBy = "pk.bookorders", cascade=CascadeType.ALL,orphanRemoval = true)
        private Set<DetailOrder> orderDetails = new HashSet<DetailOrder>();
    }

图书类

@Entity
@Table(name="BOOK",catalog = "JSPPROJECTDATABASE"){
        ...

@Id
@SequenceGenerator(name="BOOK_SEQ", sequenceName="BOOK_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="BOOK_SEQ")
@Column(name="BOOK_ID", nullable = false)
private int id; 

@OneToMany(fetch = FetchType.EAGER,mappedBy = "pk.book", cascade=CascadeType.ALL)
private Set<DetailOrder> detailOrders = new HashSet<DetailOrder>(); }

详细订单类

@Entity
@Table(name = "DETAILORDER", catalog = "JSPPROJECTDATABASE")
@AssociationOverrides({
        @AssociationOverride(name = "pk.bookorders", 
            joinColumns = @JoinColumn(name = "ORDER_ID")),
        @AssociationOverride(name = "pk.book", 
            joinColumns = @JoinColumn(name = "BOOK_ID")) })
public class DetailOrder implements Serializable{

private DetailOrderId pk = new DetailOrderId();

    @Id
    @SequenceGenerator(name="DETAIL_ORDER_SEQ", sequenceName="DETAIL_ORDER_SEQ", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DETAIL_ORDER_SEQ")
    @Column(name="DETAIL_ORDER_ID", nullable = false)
    private int id;

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "BOOK_ID")
    private Book book;

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "ORDER_ID")
    private BookOrders bookorders;

    @Column(name="QUANTITY")
    private int quantity;

    @Column(name="SUBTOTAL")
    private float subTotal;

    @EmbeddedId
    public DetailOrderId getPk() {
        return pk;
    }

    public void setPk(DetailOrderId pk) {
        this.pk = pk;
    }
}

DetailOrderId类

@Embeddable
public class DetailOrderId implements Serializable{

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "BOOK_ID")
    private Book book;

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "ORDER_ID")
    private BookOrders bookorders;
}

测试插入代码

@Test
    public void testCreateOrder() {
        System.out.println("testCreateOrder");
        BookOrders bookorders = new BookOrders();

        Customer customer = new Customer();
        customer.setId(42);

        bookorders.setCustomer(customer);
        bookorders.setRecipentName("Recipent Name");
        bookorders.setRecipentPhone("123456789");
        bookorders.setShippingAddress("Address");

        Set<DetailOrder> orderDetails = new HashSet<DetailOrder>();
        DetailOrder detailOrder = new DetailOrder();

        Book book = new Book(24);
        detailOrder.setBook(book);
        detailOrder.setQuantity(1);
        detailOrder.setSubTotal(33.99f);
        detailOrder.setOrders(bookorders);

        orderDetails.add(detailOrder);

        bookorders.setOrderDetails(orderDetails);

        BookOrders savedOrders = ordersDAO.create(bookorders);

        assertNotNull(savedOrders);
        //assertTrue(savedOrders.getId() > 0);


    }

共有1个答案

龙志勇
2023-03-14

我解决了这个问题。

DetailOrder类

public class DetailOrder implements Serializable{

    @EmbeddedId
    @AttributeOverrides({ @AttributeOverride(name = "ORDER_ID", column = @Column(name = "ORDER_ID", nullable = false)),
        @AttributeOverride(name = "BOOK_ID", column = @Column(name = "BOOK_ID", nullable = false))})
    private DetailOrderId pk = new DetailOrderId();

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "BOOK_ID", insertable = false, updatable = false, nullable = false)
    private Book book;

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "ORDER_ID", insertable = false, updatable = false, nullable = false)
    private BookOrders bookorders;  }

DetailOrderId类

@Embeddable
public class DetailOrderId implements Serializable{

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "BOOK_ID", insertable = false, updatable = false, nullable = false)
    private Book book;

    @ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "ORDER_ID", insertable = false, updatable = false, nullable = false)
    private BookOrders bookorders;

订书类

@OneToMany(fetch = FetchType.EAGER,mappedBy = "pk.bookorders", cascade=CascadeType.ALL)
    private Set<DetailOrder> orderDetails = new HashSet<DetailOrder>();

图书类

@OneToMany(fetch = FetchType.EAGER,mappedBy = "pk.book", cascade=CascadeType.ALL)
    private Set<DetailOrder> detailOrders = new HashSet<DetailOrder>();
 类似资料:
  • 问题内容: 我尝试使用Oracle数据库编写以下内部联接查询: 这给出了以下错误: 一个表的DDL为: 问题答案: 您的问题是那些有害的双引号。 Oracle SQL允许我们忽略数据库对象名称的大小写,只要我们创建它们时都使用大写的名称,或者不使用双引号即可。如果我们在脚本中使用大小写混合或小写并且将标识符括在双引号中,则当我们引用对象或其属性时,我们都被要求使用双引号和精确的大小写: tl; d

  • ORA-00904:“strdef”:无效标识符 > Oracle数据库版本为: Oracle Database 11g Enterprise Edition版本11.2.0.4.0-64位Production PL/SQL版本11.2.0.4.0-Production“Core 11.2.0.4.0 Production”TNS for Linux:版本11.2.0.4.0-Production

  • 我得到这个错误,而在Oracle数据库中执行查询: ORA-00904:“STRDEF”:无效标识符 > Oracle Database 11g Enterprise Edition 11.2.0.4.0版-64位生产PL/SQL 11.2.0.4.0版-生产“CORE 11.2.0.4.0生产”Linux版TNS:11.2.0.4.0版-生产NLSRTL 11.2.0.4.0版-生产 STRDE

  • 在PL/SQL中执行以下查询时,我得到ORA-00904:“\d$”:无效标识符错误。 我也尝试使用单引号,但仍然面临同样的错误。 有人能帮我解决这个问题吗

  • 问题内容: 1.在将row_val变量char值’Good’更新到表中时,得到无效的标识符错误2.在插入数字时,它工作正常,但字符串却出现错误3。 错误 ORA-00904:“良好”:标识符无效ORA-06512:在第43行ORA-06512:在“ SYS.DBMS_SQL”在第1721行 我想将此’good,son,r ,, happy’字符串中的每个单词插入一行中的单独列中 问题答案: 字符串

  • Oracle 11g Express Edition..创建表时出错 ORA-00904:无效标识符

  • 我已经在虚拟XP中安装了Oracle 10g,并使用 并且成功地创建了表。但是当我试图通过简单的查询获取值时,如 我得到的错误就像 ORA-00904:"bbb":无效标识符 我不能理解我在这里做错了什么。

  • 问题内容: 为什么下面的查询在oracle中不起作用? 产生“ ORA-00904:“ EO”。“ ENTITY_ID”:无效标识符”。但是,当我用精确值(例如10181)替换EO.ENTITY_ID时,它就可以工作。 更新:完整的查询如下所示: 问题答案: 如果您是基础知识的话,则 CORRELATED 可以访问相关表。但是,当有 INNER时 ,将首先尝试执行该表…因此,处于条件中的其他表将无