M
mmnnoo
Guest
One-to-one relation issue: column(should be mapped with insert="false" update="false)
Hi,
i've two db tables as follow:
CREATE TABLE `customer` (
`id` char(36) NOT NULL,
`name` varchar(50) NOT NULL,
`lastname` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `customer_detail` (
`customer_id` char(36) NOT NULL,
`creation_date` date DEFAULT NULL,
`deletion_date` date DEFAULT NULL,
PRIMARY KEY (`customer_id`),
CONSTRAINT `FK_customer_detail_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and two domain classes that map these tables
class Customer {
String name
String lastname
static hasOne = [detail: CustomerDetail]
static mapping = {
id generator: "assigned"
version false
}
static constraints = {
name maxSize: 50
lastname maxSize: 50
detail nullable: true, unique: true
}
}
class CustomerDetail {
Date creationDate
Date deletionDate
static belongsTo = [customer:Customer]
static mapping = {
id generator: "assigned", column: "customer_id", insert: false, update: false
version false
}
static constraints = {
}
}
but when I run the application (run-app) I get the following error:
Caused by MappingException: Repeated column in mapping for entity: my.data.domain.CustomerDetail column: customer_id (should be mapped with insert="false" update="false")
If I remove <id generator: "assigned", column: "customer_id", insert: false, update: false> the GORM sets the one-to-one reference on Customer.id and CustomerDetail.id but
the field customer_detail.id doesn't exists in db and I can not modify the db structure.
Is there a solutions to that?
Thank you in advance
Mono
Hi,
i've two db tables as follow:
CREATE TABLE `customer` (
`id` char(36) NOT NULL,
`name` varchar(50) NOT NULL,
`lastname` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `customer_detail` (
`customer_id` char(36) NOT NULL,
`creation_date` date DEFAULT NULL,
`deletion_date` date DEFAULT NULL,
PRIMARY KEY (`customer_id`),
CONSTRAINT `FK_customer_detail_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and two domain classes that map these tables
class Customer {
String name
String lastname
static hasOne = [detail: CustomerDetail]
static mapping = {
id generator: "assigned"
version false
}
static constraints = {
name maxSize: 50
lastname maxSize: 50
detail nullable: true, unique: true
}
}
class CustomerDetail {
Date creationDate
Date deletionDate
static belongsTo = [customer:Customer]
static mapping = {
id generator: "assigned", column: "customer_id", insert: false, update: false
version false
}
static constraints = {
}
}
but when I run the application (run-app) I get the following error:
Caused by MappingException: Repeated column in mapping for entity: my.data.domain.CustomerDetail column: customer_id (should be mapped with insert="false" update="false")
If I remove <id generator: "assigned", column: "customer_id", insert: false, update: false> the GORM sets the one-to-one reference on Customer.id and CustomerDetail.id but
the field customer_detail.id doesn't exists in db and I can not modify the db structure.
Is there a solutions to that?
Thank you in advance
Mono