没有自主主键的表间关系如何处理

山狮 山狮 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有两张表,

一张:用户基本信息表
一张:用户详细信息表

表间是一对多的关系(one-to-many关系),即一个用户基本信息表可以对应到多个详细信息,那么在这种情况下,用hibernate反转工程如何进行处理。生成的表结构总是不对。

不用SSH框架,手动写,这个项目已经能用正常的运行,添加SSH框架用反向工程自动生成就变这样了,怎么回事。


--------------------------------------------------用户基本信息表
create table customerInfo(
customerId int identity primary key,
customerName varchar(20) not null,
password varchar(20) not null,
email varchar(30) not null,
cash money default(0)
)
go
alter table customerInfo
add constraint CK_cash
check(cash>=0)
go

create table customerDetailInfo(
customerId int not null,
customerName varchar(20) not null,
tel varchar(13) not null,
email varchar(30),
address varchar(80) not null,
countMoney float,
qq varchar(12)
)
alter table customerDetailInfo
add constraint FK_customerId
foreign key(customerId) references customerInfo(customerId)
go



反转工程会自动生成三个POJO类,但是对应的只有两个.hbm.xml文件;

CustomerInfo.java POJO类如下:

public class CustomerInfo implements java.io.Serializable {

private Integer customerId;
private String customerName;
private String password;
private String email;
private Double cash;
private Set orderMains = new HashSet(0);
private Set customerDetailInfos = new HashSet(0);


public CustomerInfo() {

}

public CustomerInfo(String customerName, String password, String email) {
this.customerName = customerName;
this.password = password;
this.email = email;
}

public CustomerInfo(String customerName, String password, String email,
Double cash, Set orderMains, Set customerDetailInfos) {
this.customerName = customerName;
this.password = password;
this.email = email;
this.cash = cash;
this.orderMains = orderMains;
this.customerDetailInfos = customerDetailInfos;
}

/**
省略get set方法
*/

}


对应的CustomerInfo.hbm.xml文件

<?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.snail.dao.pojo.CustomerInfo" table="customerInfo" schema="dbo" catalog="bookStore">
<id name="customerId" type="java.lang.Integer">
<column name="customerId" />
<generator class="native"></generator>
</id>
<property name="customerName" type="java.lang.String">
<column name="customerName" length="20" not-null="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="20" not-null="true" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="30" not-null="true" />
</property>
<property name="cash" type="java.lang.Double">
<column name="cash" scale="4" />
</property>
<set name="orderMains" inverse="true">
<key>
<column name="customerId" not-null="true" />
</key>
<one-to-many class="com.snail.dao.pojo.OrderMain" />
</set>
<set name="customerDetailInfos" inverse="true">
<key>
<column name="customerId" not-null="true" />
</key>
<one-to-many class="com.snail.dao.pojo.CustomerDetailInfo" />
</set>
</class>
</hibernate-mapping>



生成的CustomerDetailInfo.java POJO类如下:

public class CustomerDetailInfo implements java.io.Serializable {

private CustomerDetailInfoId id;
private CustomerInfo customerInfo;


public CustomerDetailInfo() {
}

public CustomerDetailInfo(CustomerDetailInfoId id, CustomerInfo customerInfo) {
this.id = id;
this.customerInfo = customerInfo;
}


public CustomerDetailInfoId getId() {
return this.id;
}
//省略set get 方法

}


对应的配置文件如下


<?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.snail.dao.pojo.CustomerDetailInfo" table="customerDetailInfo" schema="dbo" catalog="bookStore">
<composite-id name="id" class="com.snail.dao.pojo.CustomerDetailInfoId">
<key-property name="customerId" type="java.lang.Integer">
<column name="customerId" />
</key-property>
<key-property name="customerName" type="java.lang.String">
<column name="customerName" length="20" />
</key-property>
<key-property name="tel" type="java.lang.String">
<column name="tel" length="13" />
</key-property>
<key-property name="email" type="java.lang.String">
<column name="email" length="30" />
</key-property>
<key-property name="address" type="java.lang.String">
<column name="address" length="80" />
</key-property>
<key-property name="countMoney" type="java.lang.Double">
<column name="countMoney" precision="53" scale="0" />
</key-property>
<key-property name="qq" type="java.lang.String">
<column name="qq" length="12" />
</key-property>
</composite-id>
<many-to-one name="customerInfo" class="com.snail.dao.pojo.CustomerInfo" update="false" insert="false" fetch="select">
<column name="customerId" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>





生成的CustomerDetailInfoId如下:

public class CustomerDetailInfoId implements java.io.Serializable {

private Integer customerId;
private String customerName;
private String tel;
private String email;
private String address;
private Double countMoney;
private String qq;

public CustomerDetailInfoId() {
}

public CustomerDetailInfoId(Integer customerId, String customerName,
String tel, String address) {
this.customerId = customerId;
this.customerName = customerName;
this.tel = tel;
this.address = address;
}

public CustomerDetailInfoId(Integer customerId, String customerName,
String tel, String email, String address, Double countMoney,
String qq) {
this.customerId = customerId;
this.customerName = customerName;
this.tel = tel;
this.email = email;
this.address = address;
this.countMoney = countMoney;
this.qq = qq;
}
}


...全文

相关推荐

无人机手势控制数据集46176张VOC+YOLO格式.zip

数据集格式:VOC格式+YOLO格式 压缩包内含:3个文件夹,分别存储图片、xml、txt文件 JPEGImages文件夹中jpg图片总计:46176 Annotations文件夹中xml文件总计:46176 labels文件夹中txt文件总计:46176 标签种类数:8 标签名称:["follow","follow_hand","land","land_hand","null","object","takeoff","takeoff-hand"] 每个标签的框数(注意yolo格式类别顺序不和这个对应,而以labels文件夹classes.txt为准): follow 框数 = 22056 follow_hand 框数 = 4038 land 框数 = 7609 land_hand 框数 = 3300 null 框数 = 2642 object 框数 = 2 takeoff 框数 = 3494 takeoff-hand 框数 = 3645 总框数:46786 图片清晰度(分辨率:像素):清晰 图片是否增强:否 标签形状:矩形框,用于目标检测识别 重要说明:暂无 特别声明:本数据集不对训练的模型或者权重文件精度作任何保证,数据集只提供准确且合理标注

不会仰游的河马君

三相光伏发电系统中MPPT和并网控制策略的研究(Simulink仿真实现)

内容概要:本文系统研究了三相光伏发电系统中的最大功率点跟踪(MPPT)与并网控制策略,深入分析光伏阵列在不同光照和温度条件下的输出特性,设计并实现了基于Simulink的完整仿真模型。该模型涵盖光伏阵列、DC-DC变换器、MPPT控制器、逆变器及锁相环等关键模块,重点验证了系统在动态环境变化下实现高效能量转换的能力,并确保并网电流符合电能质量标准。研究对比了多种MPPT算法的动态响应与稳定性表现,优化了并网控制策略以提升整体系统性能,为光伏系统的设计与控制提供了理论依据与仿真支持。; 适合人群:具备电力电子、自动控制或新能源发电基础知识的高校研究生、科研人员及从事光伏系统设计与仿真的工程技术人员。; 使用场景及目标:①用于教学与科研中深入理解光伏发电系统的MPPT原理与并网控制机制;②指导实际工程项目中光伏逆变器控制策略的设计与仿真验证;③为撰写相关学术论文或完成课程设计提供可复现的Simulink模型与理论支持。; 阅读建议:建议读者结合文中提供的Simulink仿真文件,逐步搭建系统模型,调试MPPT与并网控制参数,观察关键波形如光伏电压、电流、功率及并网电流的变化,加深对控制逻辑的理解。同时可尝试改进算法以进一步提升系统动态响应与鲁棒性。

荧光Matlab

无人驾驶网约车服务:全球市场规模、竞争格局与未来发展趋势.docx

无人驾驶网约车服务:全球市场规模、竞争格局与未来发展趋势

行业报告QY

开绕组永磁同步电机模型FOC矢量控制SVPWM仿真Simulink模型

内容概要:本文系统解读了一套完整的多机器人路径规划(MAPF)MATLAB代码库,聚焦于优先级规划算法的工程实现。该框架采用四层架构设计(几何、拓扑、调度与呈现),实现了从地图解析、Petri网建模、基于动态边权膨胀的路径规划,到时间同步冲突消解及动画可视化的全流程。核心创新包括动态边权膨胀机制、节点预留历史查表优化、几何惩罚驱动的局部同步策略以及Petri网双阶段优化方法,有效提升了大规模场景下的求解效率与可行性。文章详细阐述了各模块之间的接口契约与不变量,对比分析了三种时间同步策略的适用场景,并强调了信息前移、模块解耦与可维护性设计的重要性,为MAPF的研究与教学提供了可复现、可批判的参考文本。; 适合人群:具备一定MATLAB编程基础,从事机器人路径规划、智能调度、自动化控制等相关领域的科研人员与研究生。; 使用场景及目标:① 学习并复现多机器人路径规划中的优先级规划算法及其工程实现细节;② 深入理解动态边权膨胀、节点预留历史、局部同步等核心机制的设计原理与性能优化策略;③ 掌握Petri网建模与整数规划在路径调度中的应用,以及多智能体系统冲突消解与可视化的方法。; 阅读建议:此资源以工程化框架形式呈现,不仅关注算法逻辑,更重视模块化设计与系统集成。建议读者按照数据流顺序逐步学习,结合代码调试理解各层交互,并尝试替换不同同步策略以评估其对效率与解质量的影响,从而深入掌握大规模MAPF问题的求解范式。

荔枝科研社

高校技术转移办公室人员如何高效完成科技成果评价与推介?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论 2
收藏 已收藏
分享
返回顶部
山狮
疑难问题 22,298 成员 121,727 内容