在Spring中插入数据-CrudRepository

时间:2020-01-10 21:00:48

标签: spring

例如,我有两个实体:

minikube v1.6.2 on Ubuntu 19.10
  Selecting 'none' driver from user configuration (alternates: [])
  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
  Using the running none "minikube" VM ...
  Waiting for the host to be provisioned ...
  Preparing Kubernetes v1.17.0 on Docker '19.03.2' ...
     kubelet.resolv-conf=/run/systemd/resolve/resolv.conf
  Launching Kubernetes ...

Error starting cluster: running cmd: /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.17.0:$PATH kubeadm init phase certs all --config /var/tmp/minikube/kubeadm.yaml": /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.17.0:$PATH kubeadm init phase certs all --config /var/tmp/minikube/kubeadm.yaml": exit status 1
stdout:
[certs] Using certificateDir folder "/var/lib/minikube/certs"
[certs] Using existing ca certificate authority
[certs] Using existing apiserver certificate and key on disk

stderr:
W0110 13:53:06.531592    6051 common.go:77] your configuration file uses a deprecated API spec: "kubeadm.k8s.io/v1beta1". Please use 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.
W0110 13:53:06.532094    6051 common.go:77] your configuration file uses a deprecated API spec: "kubeadm.k8s.io/v1beta1". Please use 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.
W0110 13:53:06.533419    6051 validation.go:28] Cannot validate kube-proxy config - no validator is available
W0110 13:53:06.533440    6051 validation.go:28] Cannot validate kubelet config - no validator is available
error execution phase certs/apiserver-kubelet-client: [certs] certificate apiserver-kubelet-client not signed by CA certificate ca: crypto/rsa: verification error
To see the stack trace of this error execute with --v=5 or higher


?  minikube is exiting due to an error. If the above message is not useful, open an issue:
?  https://github.com/kubernetes/minikube/issues/new/choose
❌  Problems detected in kube-addon-manager ["c7ccb7eb00cc"]:
    error: You must be logged in to the server (error when retrieving current configuration of:
    error: You must be logged in to the server (the server has asked for the client to provide credentials)
    error: You must be logged in to the server (the server has asked for the client to provide credentials)
❌  Problems detected in kube-apiserver ["c91043e54554"]:
    I0110 20:52:44.283421       1 log.go:172] http: TLS handshake error from 127.0.0.1:47838: remote error: tls: bad certificate
    I0110 20:52:44.483603       1 log.go:172] http: TLS handshake error from 127.0.0.1:47846: remote error: tls: bad certificate
    I0110 20:52:44.549909       1 log.go:172] http: TLS handshake error from 127.0.0.1:47848: remote error: tls: bad certificate

是存储位置的实体,并且

@Builder
@Entity(name = "orders")
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    private User user;

    private Date orderDate;

    @Column(name = "status", length = 60)
    private String status;

    @OneToMany(mappedBy = "order")
    private Collection<OrderPosition> orderPositions;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "address_id", referencedColumnName = "id")
    private OrderAddress orderAddress;
}

按顺序存储单个职位,问题是: 我可以通过这种方式将行保存在数据库中吗(示例):

@Builder
@Entity(name = "order_position")
public class OrderPosition {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id", referencedColumnName = "id", nullable = false)
    private Order order;

    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false)
    private Product product;

    private Integer count;
    private BigDecimal unitPrice;
}

如果没有,我应该怎么做?

0 个答案:

没有答案