微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

复合键级联集null弹簧jpa

如何解决复合键级联集null弹簧jpa

我有两个具有一对多关系的实体

孩子有一个组合键

当我尝试使用级联通过父项插入子项时

返回空异常

iam使用spring jpa,hibernate,springboot

父母

 @IntRange(from = 0,to = 3)
fun getConnectionType(context: Context): Int {
    var result = 0 // Returns connection type. 0: none; 1: mobile data; 2: wifi
    val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

        val capabilities =
            cm.getNetworkCapabilities(cm.activeNetwork)
        if (capabilities != null) {
            if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
                result = 2
            } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
                result = 1
            } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
                result = 3
            }

        }
    } else {

        val activeNetwork = cm.activeNetworkInfo
        if (activeNetwork != null) {
            // connected to the internet
            if (activeNetwork.type === ConnectivityManager.TYPE_WIFI) {
                result = 2
            } else if (activeNetwork.type === ConnectivityManager.TYPE_MOBILE) {
                result = 1
            } else if (activeNetwork.type === ConnectivityManager.TYPE_VPN) {
                result = 3
            }
        }
    }
    return result
}

孩子

    @Entity
@Table(name="ITEM",schema="MGITCLOTHES2020",uniqueConstraints = {@UniqueConstraint(columnNames="CODE_COMPANY"),@UniqueConstraint(columnNames="NAME")} 
)
public class Item implements java.io.Serializable {

    @Id    
    @SequenceGenerator(name = "ITEM_ID_GENERATOR",allocationSize = 1,sequenceName = "SEQ_ITEM")
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "ITEM_ID_GENERATOR")
    @Column(name = "ID",unique = true,nullable = false,precision = 22,scale = 0)
    private Long id;

    @OnetoMany(fetch = FetchType.LAZY,mappedBy = "item",cascade = CascadeType.ALL)
    private List<Itemunit> itemunits = new ArrayList<Itemunit>(0);

    public Item() {
    }

我正在使用Embedded ID的此复合密钥

@Entity
@Table(name = "ITEM_UNIT",schema = "MGITCLOTHES2020"
)
public class Itemunit implements java.io.Serializable {

    @EmbeddedId
    @AttributeOverrides({
    @AttributeOverride(name = "unitId",column = @Column(name = "UNIT_ID",scale = 0)),@AttributeOverride(name = "itemId",column = @Column(name = "ITEM_ID",scale = 0))})
    private ItemunitId id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ITEM_ID",insertable = false,updatable = false)
    private Item item;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "UNIT_ID",updatable = false)
    private Unit unit;

    public Itemunit() {
    }

错误消息是 oracle.jdbc.OracleDatabaseException:ORA-01400:?? ???? ?????? NULL((“ MGITCLOTHES2020”。“ ITEM_UNIT”。“ ITEM_ID”) 在oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513)〜[ojdbc8-19.3.0.0.jar:19.3.0.0.0] 在oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461)〜[ojdbc8-19.3.0.0.jar:19.3.0.0.0] 在oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104)〜[ojdbc8-19.3.0.0.jar:19.3.0.0.0] 预先感谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。