如何坚持的salesorder实体,customerlookup空如何节省空孩子多到一的关系
的关系是在销售订单实体
@Column(name="customer_id")
private int customerId;
@ManyToOne
@JoinColumn(name="customer_id", referencedColumnName="customer_id", columnDefinition="integer", unique=true, nullable=true, insertable=false, updatable=false)
@NotFound(action=NotFoundAction.IGNORE)
private Customer customerLookup;
客户实体
@Id
@Column(name="customer_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int customerId
我总是有错误:没有给定标识符的行 因为customerLookup设置为null。 基本上我需要通过设置CUSTOMER_ID保存销售订单没有客户数据和customerlookup为空(无客户表/实体所需的更改)
表结构
CREATE TABLE `tb_so` (
`so_id` int(11) NOT NULL AUTO_INCREMENT,
`so_code` varchar(45) DEFAULT NULL,
`so_created` datetime DEFAULT NULL,
`shipping_date` datetime DEFAULT NULL,
`customer_id` int(11) DEFAULT '0',
`walk_in_cust_det` varchar(255) DEFAULT NULL,
`so_type` varchar(45) DEFAULT NULL,
`status` varchar(45) DEFAULT NULL,
`created_by` int(11) DEFAULT '0',
`created_date` datetime DEFAULT NULL,
`updated_by` int(11) DEFAULT '0',
`updated_date` datetime DEFAULT NULL,
`remarks` varchar(255) DEFAULT NULL,
PRIMARY KEY (`so_id`)
);
CREATE TABLE `tb_customer` (
`customer_id` int(11) NOT NULL AUTO_INCREMENT,
`customer_name` varchar(45) DEFAULT NULL,
`address` varchar(45) DEFAULT NULL,
`city` varchar(45) DEFAULT NULL,
`phone` varchar(45) DEFAULT NULL,
`npwp_num` varchar(45) DEFAULT NULL,
`price_level_id` int(11) DEFAULT NULL,
`status` varchar(15) DEFAULT NULL,
`remarks` varchar(45) DEFAULT NULL,
`created_by` int(11) DEFAULT '0',
`created_date` datetime DEFAULT NULL,
`updated_by` int(11) DEFAULT '0',
`updated_date` datetime DEFAULT NULL,
PRIMARY KEY (`customer_id`)
);
感谢
如果cutomerId应该是null,那么它不能是'int':原始类型不可为空。它应该是一个整数。但更重要的是,它甚至不应该在那里。你应该拥有的是ManyToOne协会。 'SalesOrder.getCustomerLookup()。getCustomerId()'允许从SalesOrder获取customerId。所以删除无用的referenceColumnName,columnDefinition,可为null,可插入和可更新的属性。并删除唯一=“真”:如果它是独一无二的,你不会有一个ManyToOne,而是一个OneOne。 –
那么你是否说,salesorder实体中的customerId不应该是int? – GitzJoey
不,我是说它不应该是一个整数。如果有,它应该是一个整数。但它应该不会在那里摆在首位。重新阅读我的评论。 –