两班:
<class name="SpreadsheetImportTemplate" table="spreadsheetimport_template">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native" />
</id>
<property name="name" type="java.lang.String" column="name" not-null="true" length="100" />
<many-to-one name="creator" class="org.openmrs.User" not-null="true" />
<property name="created" type="java.util.Date" column="date_created" not-null="true"
length="19" />
<many-to-one name="modifiedBy" column="changed_by" class="org.openmrs.User" not-null="false" />
<property name="modified" type="java.util.Date" column="date_changed" not-null="false" length="19" />
<!-- Associations -->
<!-- bi-directional one-to-many association to SpreadsheetImportTemplateColumn -->
<bag name="columns" cascade="all-delete-orphan" inverse="true">
<key column="template_id" not-null="true" />
<one-to-many class="SpreadsheetImportTemplateColumn" />
</bag>
</class>
<class name="SpreadsheetImportTemplateColumn" table="spreadsheetimport_template_column">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="template" class="SpreadsheetImportTemplate" column="template_id" />
<property name="columnName" type="java.lang.String" column="column_name" length="100" not-null="true" />
<property name="dbTableDotColumn" type="java.lang.String" column="db_table_dot_column" length="100" not-null="true"/>
<property name="extraData" type="java.lang.String" column="extra_data" length="100" not-null="false"/>
</class>
在java,两人都接过了各自的采集器和板块:
public class SpreadsheetImportTemplate {
Integer id;
String name;
Collection<SpreadsheetImportTemplateColumn> columns = new ArrayList<SpreadsheetImportTemplateColumn>();
Date created;
Date modified;
User creator;
User modifiedBy;
public SpreadsheetImportTemplate() {
}
...
public class SpreadsheetImportTemplateColumn {
Integer id;
SpreadsheetImportTemplate template;
String columnName;
String dbTableDotColumn;
String extraData;
public SpreadsheetImportTemplateColumn() {
}
...
然而,如果我们有<条码>。 SpreadsheetImportTemplate model with somenels, and we do a template.remove (0)
and subsequently a Hibernate
saveOrUpdate
, the relevant SpreadetImportTemplateColumn
do
感谢任何帮助。
Fyi, 这里是创建数据库的相关结构:
CREATE TABLE IF NOT EXISTS `spreadsheetimport_template` (
`id` int(32) NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`creator` int(11) NOT NULL default 0 ,
`date_created` datetime NOT NULL default 0000-00-00 00:00:00 ,
`changed_by` int(11) default NULL,
`date_changed` datetime default NULL,
PRIMARY KEY (`id`),
KEY `User who wrote this spreadsheet template` (`creator`),
KEY `User who changed this spreadsheet template` (`changed_by`),
CONSTRAINT `User who wrote this spreadsheet template` FOREIGN KEY (`creator`) REFERENCES `users` (`user_id`),
CONSTRAINT `User who changed this spreadsheet template` FOREIGN KEY (`changed_by`) REFERENCES `users` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `spreadsheetimport_template_column` (
`id` int(32) NOT NULL auto_increment,
`template_id` int(32) NOT NULL default 0 ,
`column_name` varchar(100) NOT NULL,
`db_table_dot_column` varchar(100) NOT NULL,
`extra_data` varchar(100),
PRIMARY KEY (`id`),
KEY `Spreadsheet template to which this column belongs` (`template_id`),
CONSTRAINT `Spreadsheet template to which this column belongs` FOREIGN KEY (`template_id`) REFERENCES `spreadsheetimport_template` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;