- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试使用 hibernate 创建一对一映射并保存 SQL 数据库,但我运行我的项目时出现以下错误:
Initial SessionFactory creation failed.org.hibernate.AnnotationException: Unknown mappedBy in: mdl.Complaint.jobDone, referenced property unknown: mdl.JobDone.jobDone
Exception in thread "main" java.lang.ExceptionInInitializerError
at config.HibernateUtil.buildSessionFactory(HibernateUtil.java:19)
at config.HibernateUtil.<clinit>(HibernateUtil.java:8)
at application.JD_Comp.main(JD_Comp.java:22)
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: mdl.Complaint.jobDone, referenced property unknown: mdl.JobDone.jobDone
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:159)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1689)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1396)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1829)
at config.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
... 2 more
有我的映射类:
@Entity
@Table(name = "Complaint", catalog = "jobcard")
public class Complaint implements Serializable{
private Integer complaint_id;
private String nature;
private String instruction;
private JobDone jobDone;
/**
* @return the complaint_id
*/
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "complaint_id", unique = true, nullable = false)
public Integer getComplaint_id() {
return complaint_id;
}
/**
* @param complaint_id the complaint_id to set
*/
public void setComplaint_id(Integer complaint_id) {
this.complaint_id = complaint_id;
}
/**
* @return the nature
*/
public String getNature() {
return nature;
}
/**
* @param nature the nature to set
*/
public void setNature(String nature) {
this.nature = nature;
}
/**
* @return the instruction
*/
public String getInstruction() {
return instruction;
}
/**
* @param instruction the instruction to set
*/
public void setInstruction(String instruction) {
this.instruction = instruction;
}
/**
* @return the jobDone
*/
@OneToOne(fetch = FetchType.LAZY, mappedBy = "jobDone", cascade = CascadeType.ALL)
public JobDone getJobDone() {
return jobDone;
}
/**
* @param jobDone the jobDone to set
*/
public void setJobDone(JobDone jobDone) {
this.jobDone = jobDone;
}
}
其他类:
@Entity
@Table(name = "JobDone", catalog = "jobcard", uniqueConstraints = {
@UniqueConstraint(columnNames = "nature"),
@UniqueConstraint(columnNames = "amount") })
public class JobDone implements Serializable{
private Integer jobDone_id;
private String nature;
private Integer amount;
private Complaint complaint;
/**
* @return the jobDone_id
*/
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "Complaint"))
@Id
@GeneratedValue(generator = "generator")
@Column(name = "jobDone_id", unique = true, nullable = false)
public Integer getJobDone_id() {
return jobDone_id;
}
/**
* @param jobDone_id the jobDone_id to set
*/
public void setJobDone_id(Integer jobDone_id) {
this.jobDone_id = jobDone_id;
}
/**
* @return the nature
*/
public String getNature() {
return nature;
}
/**
* @param nature the nature to set
*/
public void setNature(String nature) {
this.nature = nature;
}
/**
* @return the amount
*/
public Integer getAmount() {
return amount;
}
/**
* @param amount the amount to set
*/
public void setAmount(Integer amount) {
this.amount = amount;
}
/**
* @return the complaint
*/
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Complaint getComplaint() {
return complaint;
}
/**
* @param complaint the complaint to set
*/
public void setComplaint(Complaint complaint) {
this.complaint = complaint;
}
}
SQL查询:
CREATE DATABASE jobcard;
USE jobcard;
CREATE TABLE Complaint(
jobNumber varchar(100),
complaint_id int(10) primary key NOT NULL AUTO_INCREMENT,
nature varchar(200),
instruction varchar(200),
constraint foreign key(jobNumber) references JobCard(jobNumber)
on delete cascade on update cascade
);
CREATE TABLE JobDone(
complaint_id int(10),
jobDone_id int(10) primary key NOT NULL AUTO_INCREMENT,
nature varchar(200),
amount int,
constraint foreign key(complaint_id) references Complaint(complaint_id)
on delete cascade on update cascade
);
然后我创建了 hibernate.cfg.xml 文件并映射了两个类的完全限定类名。为什么我会收到此错误。
更新
这是工作
投诉类:
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public JobDone getJobDone() {
return jobDone;
}
JobDone 类:
@OneToOne(fetch = FetchType.LAZY, mappedBy = "jobDone", cascade = CascadeType.ALL)
public Complaint getComplaint() {
return complaint;
}
最佳答案
显然,问题是您在 JobDone
中没有属性 jobDone
。你可以使用这个映射
public class Compilant {
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public JobDone getJobDone() {
return jobDone;
}
}
您将在 Complaint
中有一个指向 JobDone
的外键。您可以从 JobDone
中删除 Compilant
属性。
如果你想在 JobDone
中也有一个 Complaint
的关联(这不是很方便)
public class JobDone {
@OneToOne(fetch = FetchType.LAZY)
public Complaint getComplaint() {
return complaint;
}
}
如果你只想在JobDone
public class Compilant {
@OneToOne(fetch = FetchType.LAZY, mappedBy = "complaint" cascade = CascadeType.ALL)
public JobDone getJobDone() {
return jobDone;
}
}
public class JobDone {
@OneToOne(fetch = FetchType.LAZY)
public Complaint getComplaint() {
return complaint;
}
}
关于java - org.hibernate.AnnotationException : Unknown mappedBy in: mdl. Complaint.jobDone,引用属性未知 : mdl. JobDone.jobDone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35646042/
我有一个交叉表函数,我过去曾多次成功使用它,但现在它在最后转储所有数据,而不是将其旋转到输出表中。它似乎无法找到交叉表。我通过以下方式对其进行了研究; 如果 tablefunc 不存在则创建扩展; -
表1(客户表) Id, CustomerId, IsKnownCustomer,phonemacaddress 1, 空 0 00:9a:34:cf:a4 2, 004024 1 00:6f:64:c
知道为什么我总是收到这个烦人且无用的错误代码/描述吗? Failed to pull image myapidemodocker.azurecr.io/apidemo:v4.0: rpc error:
我正在进行 PHP 登录,并且之前可以正常工作,但我尝试使用户名功能不区分大小写,但此后代码一直无法正常工作。我删除了我添加的所有内容,以尝试使其不区分大小写,即 strtolower()。页面上显示
有人会帮助我提供有关此错误的任何可能信息吗?原因?登录?在哪里寻找/开始? Cannot use output buffering in output buffering display handl
我已经添加了这样的脚本 我在我的 test.js 中做了这个 var app = angular.module('MyApp', ['ngRoute']).config
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我有这个sql语句: selectAllUsersByCriteria = 连接.prepareStatement( “从用户那里选择*?=?” ); 下面的方法运行该语句: public Array
我有一个白色的 EditText,在 Android 3.1 及更高版本中,光标不显示(因为它也是白色的)。有关信息,我使用 android:background="@android:drawable
我正在尝试使用 Keras 实现深度学习模型。但是我有一个未知形状实现的问题。我一直在寻找类似的错误,但没有找到。 这是我的代码。 Xhome = dataset[:,32:62] Xaway = d
关注此introduction可以通过导入命名空间 System.Xml 来使用 XMLReader 类。在我的 Visual Studio 项目中,我使用 .NET 4.0,但 System.Xml
我有一个动态链接库的程序。该程序将函数指针传递给该库以执行。 但是 ubsan(Undefined Behavior Sanitizer)指定指针位于错误的函数类型上。那只会发生 如果回调函数有一个类
我正在尝试在我的 Swift SpriteKit 应用程序中使用 AVAudioSession。我遇到了奇怪的“未声明类型”问题。例如…… import AVFoundation var audioS
如果在编译期间(在实际编译和运行程序之前)其参数之一的值已知/未知,如何专门化模板函数? 我还不知道怎么做。 想法 1: #include #include int main(void){
我看到一些人的代码是这样的: while (!(baseType == typeof(Object))) { .... baseType = baseType.BaseType;
我正在尝试使用 GoColly 框架获取所有 HREF 链接,但是只允许任何域的 url 为根 URL 或子域(否路径)。我已经注释掉了我的 REGEXP。文件扩展名没有事情。我只是在“/”之后不想要
我有一个包含多个实体的数据库,特别是 Book 和 User。它们之间存在这样的 ManyToMany 关系: 书: @Entity @Table(name = "Books") public cla
如果我将范围的初始部分设置为 Range("A:A"),如何确保将整行传递给排序? 数据 id、fname、mname、lname、后缀、状态、位置、时区 通过在 id 中搜索起点和终点来选择范围。
我对kubernetes很陌生,而对于docker来说就不那么多了。 我一直在研究示例,但是我对自动缩放器(似乎无法缩放)感到困惑。 我在这里通过示例https://kubernetes.io/doc
我在 ChildWindow 中使用 SL Toolkit 5 中的 BusyIndicator 控件。 在某些解决方案中,它可以工作,但在其他解决方案中,使用完全相同的代码(至少看起来),我在运
我是一名优秀的程序员,十分优秀!