First the ddl language of the table used with foreign key as :
CREATE TABLE `t_operation_log` (
`id` BIGINT(24) NOT NULL AUTO_INCREMENT,
`resourceId` BIGINT(24) NOT NULL,
`systemlogId` BIGINT(24) NOT NULL,
`operationTime` DATE DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `resourceId` (`resourceId`),
KEY `systemlogId` (`systemlogId`),
CONSTRAINT `t_operation_log_fk1` FOREIGN KEY (`systemlogId`) REFERENCES `t_system_log` (`id`),
CONSTRAINT `t_operation_log_fk` FOREIGN KEY (`resourceId`) REFERENCES `t_resource` (`id`)
)ENGINE=InnoDB
AUTO_INCREMENT=4 CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'
then the xml of the mapping is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.alba.permission.domain.Resource" table="t_resource" dynamic-insert="true" dynamic-update="true">
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<property name="url" type="string" not-null="true" />
<property name="resourceType" type="string" not-null="true" />
</class>
<class name="com.alba.permission.domain.OperationLog" table="t_operation_log" dynamic-insert="true" dynamic-update="true">
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<property name="operationTime" type="java.util.Date" />
<many-to-one name="resource" class="com.alba.permission.domain.Resource" column="RESOURCEID" unique="true" />
<many-to-one name="systemLog" class="com.alba.permission.domain.SystemLog" column="SYSTEMLOGID" unique="true"/>
</class>
<class name="com.alba.permission.domain.SystemLog" table="t_system_log" dynamic-insert="true" dynamic-update="true">
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<property name="logonUserIp" type="string" not-null="true" />
<property name="logonTime" type="java.util.Date" not-null="false" />
<property name="logoffTime" type="java.util.Date" not-null="false" />
<property name="logonUserId" type="java.lang.Long" not-null="true"/>
</class>
</hibernate-mapping>
then test code are:
Resource resource = new Resource();
OperationLog operationLog = new OperationLog();
SystemLog systemLog = new SystemLog();
resource.setUrl(operationUrl);
resource.setResourceType("Button");
facade.getPermissionService().addOperationLog(resource);
systemLog.setLogonUserIp(currentHostIp);
systemLog.setLogonUserId(user.getId());
facade.getPermissionService().addOperationLog(systemLog);
operationLog.setOperationTime(new Date());
operationLog.setResource(resource);
operationLog.setSystemLog(systemLog);
facade.getPermissionService().addOperationLog(operationLog);
The problem may happend:
1.if before add operationLog ,systemLog and resource log doesnot add,the exception will be thrown
2.here should use many to one,not one to one mapping,remembering
分享到:
相关推荐
一对一关联分为两种类型:共享主键关联(Primary Key Join)和唯一外键关联(Unique Foreign Key Join)。在本例中,我们讨论的是后者,即通过一个独立的外键字段在两个表之间建立一对一的关系。 ### 2. 唯一外键...
- `foreign-key`:指定外键。 - `sql-type`:指定SQL数据类型。 - `check`:指定检查约束。 - `<generator>`:指定主键生成策略。 - `increment`:自动增长。 - `identity`:数据库自增。 - `sequence`:使用...
- **`foreign-key`**: 外键名称。 - **其他属性**: - **`insert`**: 是否允许在插入操作中更新该属性。 - **`update`**: 是否允许在更新操作中更新该属性。 - **`mutable`**: 是否可变。 - **`use-in-toString...
<one-to-one name="student" class="com.example.Student" foreign-key="student_id"/> </hibernate-mapping> ``` **解释**: - `one-to-one`元素用于表示一对一关联。 - `constraint="unique"`表示在学生表中的...
技术运维-机房巡检表及巡检说明
第四次算法分析与设计整理
图像处理项目实战
该资源为jaxlib-0.4.18-cp311-cp311-macosx_11_0_arm64.whl,欢迎下载使用哦!
搭建说明. 运行环境 php5.6 mysql5.6 扩展sg11 前置条件: 前后端分离,需要准备两个域名,一个后台域名,一个前端域名 后端源码修改(cs2.ijiuwu.com批量替换改为你的后端域名)数据库修改(cs3.ijiuwu.com批量替换为你的前端域名)1、创建后台站点,上传后台源码并解压到根目录2、创建前端站点,上传前端源码并解压到根目录 3、创建数据库上传并导入数据库文件 4、修改数据库信息: 后台:app/database.php 前端:application/database.php 前端站点设置 伪静态thinkphp 运行目录public 关闭防跨站 访问后台域名/admin.php进入后台管理 admin 123456 系统-》系统设置-》附件设置-》Web服务器URL 改为你的前端域名 系统-》清前台缓存 改为你的前端域名 点击刷新缓存
【毕业答辩】爆款黑板风教育文艺毕业论文答辩通用模板.pptx
1、文件内容:systemd-devel-219-78.el7_9.9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/systemd-devel-219-78.el7_9.9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
win32汇编环境,对 WM-MOUSEMOVE 消息的理解
车牌识别项目
UE项目开发过程中的一些快捷脚本
lab1的words.txt文件
python、yolo、pytorch
人工智能、大语言模型相关学习资料
图像处理项目实战
python、yolo、pytorch
车牌识别项目