gpt4 book ai didi

java - 如何在标准API中编写DDL?

转载 作者:行者123 更新时间:2023-12-02 08:31:11 24 4
gpt4 key购买 nike

最佳答案

Criteria API 的文档仅描述查询,因为 Criteria API 不是为 DDL 操作而设计的。事实上,我什至会说整个 JPA API 并不是真正为此而设计的。

顺便说一句,另一个问题的代码不显示 DDL 操作,它显示 JPA 2.0 规范中描述的批量 DML 操作:

4.10 Bulk Update and Delete Operations

Bulk update and delete operations apply to entities of a single entity class (together with its subclasses, if any). Only one entity abstract schema type may be specified in the FROM or UPDATE clause.

The syntax of these operations is as follows:

update_statement ::=update_clause [where_clause]update_clause ::= UPDATE entity_name [[AS] identification_variable]                     SET update_item {, update_item}*update_item ::= [identification_variable.]{state_field | single_valued_object_field} =                     new_valuenew_value ::=       scalar_expression |       simple_entity_expression |       NULLdelete_statement ::= delete_clause [where_clause] delete_clause ::= DELETE FROM entity_name [[AS] identification_variable]

The syntax of the WHERE clause is described in Section 4.5.

A delete operation only applies to entities of the specified class and its subclasses. It does not cascade to related entities.

The new_value specified for an update operation must be compatible in type with the field to which it is assigned.

Bulk update maps directly to a database update operation, bypassing optimistic locking checks. Portable applications must manually update the value of the version column, if desired, and/or manually validate the value of the version column.

The persistence context is not synchronized with the result of the bulk update or delete.

Caution should be used when executing bulk update or delete operations because they may result in inconsistencies between the database and the entities in the active persistence context. In general, bulk update and delete operations should only be performed within a transaction in a new persistence context or before fetching or accessing entities whose state might be affected by such operations.

Examples:

DELETE
FROM Customer c
WHERE c.status = ‘inactive’

DELETE
FROM Customer c
WHERE c.status = ‘inactive’
AND c.orders IS EMPTY

UPDATE customer c
SET c.status = ‘outstanding’
WHERE c.balance < 10000

关于java - 如何在标准API中编写DDL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3333668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com