Please explain about: insertable=false, updatable=false

本文探讨了在实体关系中如何通过注解实现责任的正确分配,例如在Address实体中使用@Column(insertable=false, updatable=false)来表明Address实体不负责创建或更新与其关联的Person实体。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If a field is annotated insertable=false, updatable=false, doesnt it mean that you cannot insert value nor change the existing value? Why would u want to do that?

Do you mean something like this BalusC?

@Entity
public class Person {

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

    @OneToMany(mappedBy="person", cascade=CascadeType.ALL)
    private List<Address> addresses;
}
@Entity
public class Address {

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

    @ManyToOne
    @JoinColumn(name="ADDRESS_FK")
    @Column(insertable=false, updatable=false)
    private Person person;
}

You would do that when the responsibility of creating/udpating the related entity in question isn’t in the current entity. E.g. you have a Person and an Address. You’d like to add insertable=false, updatable=false to the @OneToMany relationship with the Person entity in the Address entity, simply because it’s not the responsibility of the Address entity to create or update a Person. It’s the other way round. This is not really a technical, but more a semantic/natural decision.

### VBA Excel Sort Order `xlAscending` No Header Example and Explanation In the context of using VBA to manipulate Excel worksheets, sorting data without headers can be achieved by specifying parameters within the `Sort` method carefully. The provided code snippet demonstrates a subroutine that sorts each worksheet in an active workbook from row 3 downwards because rows 1 and 2 are presumed to contain titles or other non-sortable information. The following adjusted version focuses on performing a simple ascending sort operation starting at cell A3 assuming there is no header: ```vba Sub SimpleAscendingSort() Dim ws As Worksheet Set ws = ActiveSheet With ws.Sort .SortFields.Clear .SortFields.Add Key:=ws.Range("A3"), _ SortOn:=xlSortOnValues, _ Order:=xlAscending, _ DataOption:=xlSortNormal ' Define range as all used cells excluding first two rows. .SetRange ws.Range("A3:A" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row) ' Specify whether dataset has headers (in this case it does not). .Header = xlNo ' Apply changes. .Apply End With End Sub ``` This script initializes a new sort object associated with the current sheet (`ActiveSheet`). It clears any existing sort fields before adding one based upon column A's values beginning at row 3. By setting `.Header=xlNo`, the algorithm treats every line equally during processing[^1]. For scenarios where only specific columns need ordering while preserving others' relative positions, adjusting the `Key` parameter accordingly will suffice. Additionally, expanding beyond single-column criteria involves appending more keys via additional calls like `.SortFields.Add`. --related questions-- 1. How would you modify the given macro if multiple sheets required different primary sort keys? 2. What adjustments should be made when including both ascending and descending orders across various columns simultaneously? 3. Can this approach handle large datasets efficiently? If not, what optimizations could improve performance? 4. Is it possible to incorporate error handling into these macros for robustness against unexpected situations such as empty ranges? 5. Could someone explain how to extend this functionality to include secondary and tertiary sort levels?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值