- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在hibernate中进行一对多映射,但它显示异常,我尝试了很多但找不到解决方案
我有下面两张表
deptno -- 数字主键
dname -- varchar2(10)
loc -- varchar2(10)
empno -- 数字主键
用户名 -- varchar2(10)
deptno -- number(10) 外键
当我没有在 Dept.java 类上添加 @Entity 注释时,我会低于堆栈跟踪
21:35:11.554 [main] DEBUG o.h.i.f.DefaultIdentifierGeneratorFactory - Registering IdentifierGenerator strategy [enhanced-table] -> [class org.hibernate.id.enhanced.TableGenerator]
21:35:11.554 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
21:35:11.554 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
21:35:11.632 [main] DEBUG org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
21:35:11.632 [main] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
21:35:11.632 [main] DEBUG org.hibernate.util.DTDEntityResolver - attempting to resolve on classpath under org/hibernate/
21:35:11.632 [main] DEBUG org.hibernate.util.DTDEntityResolver - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:XE
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - hibernate.connection.username=test
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - hibernate.connection.password=test
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - session-factory config [null] named class [com.beans.Employee] for mapping
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - session-factory config [null] named class [com.beans.Dept] for mapping
21:35:11.663 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - properties: {hibernate.connection.password=test, java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=C:\Program Files\Java\jdk1.7.0_17\jre\bin, java.vm.version=23.7-b01, hibernate.connection.username=test, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.script=, user.country=US, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=E:\javahyd\eclipse_new_hibernate\One_Many1, java.runtime.version=1.7.0_17-b02, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jdk1.7.0_17\jre\lib\endorsed, os.arch=amd64, java.io.tmpdir=C:\Users\rajeev\AppData\Local\Temp\, line.separator=
, java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 7, sun.jnu.encoding=Cp1252, java.library.path=C:\Program Files\Java\jdk1.7.0_17\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.7.0_17/bin/../jre/bin/server;C:/Program Files/Java/jdk1.7.0_17/bin/../jre/bin;C:/Program Files/Java/jdk1.7.0_17/bin/../jre/lib/amd64;C:\Windows\SYSTEM32\WBEM;C:\Program Files\Java\jdk1.7.0_17\bin;C:\ORACLEXE\APP\ORACLE\PRODUCT\10.2.0\SERVER\BIN;.;.;C:\PROGRAM FILES\MYSQL\MYSQL SERVER 5.5\BIN;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\Dell\DW WLAN Card;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\apache-maven-3.2.1\bin;C:\Windows\System32;.;E:\sts\sts-bundle\sts-3.6.0.M1;;., java.specification.name=Java Platform API Specification, java.class.version=51.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=6.1, user.home=C:\Users\rajeev, user.timezone=Asia/Calcutta, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.7, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, java.class.path=E:\javahyd\eclipse_new_hibernate\One_Many1\target\classes;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\annotations-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\catalina-ant.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\catalina-ha.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\catalina-tribes.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\catalina.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\ecj-3.7.2.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\el-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jasper-el.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jasper.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-coyote.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-dbcp.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-i18n-es.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-i18n-fr.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-i18n-ja.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-jdbc.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\tomcat-util.jar;C:\Users\rajeev\.m2\repository\ch\qos\logback\logback-core\1.1.2\logback-core-1.1.2.jar;C:\Users\rajeev\.m2\repository\ch\qos\logback\logback-classic\1.1.2\logback-classic-1.1.2.jar;C:\Users\rajeev\.m2\repository\org\slf4j\slf4j-api\1.7.6\slf4j-api-1.7.6.jar;C:\Users\rajeev\.m2\repository\com\myoracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar;C:\Users\rajeev\.m2\repository\org\hibernate\hibernate-core\3.6.10.Final\hibernate-core-3.6.10.Final.jar;C:\Users\rajeev\.m2\repository\antlr\antlr\2.7.6\antlr-2.7.6.jar;C:\Users\rajeev\.m2\repository\commons-collections\commons-collections\3.1\commons-collections-3.1.jar;C:\Users\rajeev\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\rajeev\.m2\repository\org\hibernate\hibernate-commons-annotations\3.2.0.Final\hibernate-commons-annotations-3.2.0.Final.jar;C:\Users\rajeev\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.0-api\1.0.1.Final\hibernate-jpa-2.0-api-1.0.1.Final.jar;C:\Users\rajeev\.m2\repository\javax\transaction\jta\1.1\jta-1.1.jar;C:\Users\rajeev\.m2\repository\javassist\javassist\3.12.1.GA\javassist-3.12.1.GA.jar, user.name=rajeev, hibernate.bytecode.use_reflection_optimizer=false, java.vm.specification.version=1.7, sun.java.command=com.test.Test, java.home=C:\Program Files\Java\jdk1.7.0_17\jre, sun.arch.data.model=64, hibernate.dialect=org.hibernate.dialect.Oracle10gDialect, hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:XE, user.language=en, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.7.0_17, java.ext.dirs=C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext;C:\Windows\Sun\Java\lib\ext, sun.boot.class.path=C:\Program Files\Java\jdk1.7.0_17\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_17\jre\classes, java.vendor=Oracle Corporation, file.separator=\, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=amd64}
21:35:11.663 [main] DEBUG org.hibernate.cfg.Configuration - Preparing to build session factory with filters : {}
21:35:11.741 [main] DEBUG org.hibernate.cfg.Configuration - Processing hbm.xml files
21:35:11.741 [main] DEBUG org.hibernate.cfg.Configuration - Process annotated classes
21:35:11.756 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.beans.Employee
21:35:11.789 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3DiscriminatorColumn{logicalColumnName'DTYPE', discriminatorTypeName='string'}
21:35:11.804 [main] DEBUG org.hibernate.cfg.AnnotationBinder - no value specified for 'javax.persistence.sharedCache.mode'; using UNSPECIFIED
21:35:11.820 [main] DEBUG o.h.cfg.annotations.EntityBinder - Import with entity name Employee
21:35:11.820 [main] INFO o.h.cfg.annotations.EntityBinder - Bind entity com.beans.Employee on table employee1
21:35:11.867 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table=org.hibernate.mapping.Table(employee1), mappingColumn=empno, insertable=true, updatable=true, unique=false}
21:35:11.882 [main] DEBUG o.h.cfg.annotations.PropertyBinder - binding property empno with lazy=false
21:35:11.882 [main] DEBUG o.h.c.annotations.SimpleValueBinder - building SimpleValue for empno
21:35:11.882 [main] DEBUG o.h.cfg.annotations.PropertyBinder - Building property empno
21:35:11.898 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3JoinColumn{logicalColumnName='deptno', referencedColumn='', mappedBy=''}
21:35:11.898 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table=org.hibernate.mapping.Table(employee1), mappingColumn=dept, insertable=true, updatable=true, unique=false}
21:35:11.898 [main] DEBUG o.h.cfg.annotations.PropertyBinder - Building property dept
21:35:11.898 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table=org.hibernate.mapping.Table(employee1), mappingColumn=deptno, insertable=true, updatable=true, unique=false}
21:35:11.898 [main] DEBUG o.h.cfg.annotations.PropertyBinder - binding property deptno with lazy=false
21:35:11.898 [main] DEBUG o.h.c.annotations.SimpleValueBinder - building SimpleValue for deptno
21:35:11.898 [main] DEBUG o.h.cfg.annotations.PropertyBinder - Building property deptno
21:35:11.898 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table=org.hibernate.mapping.Table(employee1), mappingColumn=userName, insertable=true, updatable=true, unique=false}
21:35:11.898 [main] DEBUG o.h.cfg.annotations.PropertyBinder - binding property userName with lazy=false
21:35:11.898 [main] DEBUG o.h.c.annotations.SimpleValueBinder - building SimpleValue for userName
21:35:11.898 [main] DEBUG o.h.cfg.annotations.PropertyBinder - Building property userName
21:35:11.898 [main] DEBUG o.h.c.annotations.SimpleValueBinder - Setting SimpleValue typeName for empno
21:35:11.898 [main] DEBUG o.h.c.annotations.SimpleValueBinder - Setting SimpleValue typeName for deptno
21:35:11.898 [main] DEBUG o.h.c.annotations.SimpleValueBinder - Setting SimpleValue typeName for userName
21:35:11.898 [main] DEBUG org.hibernate.cfg.Configuration - processing fk mappings (*ToOne and JoinedSubclass)
Exception in thread "main" org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.beans.Employee.dept references an unknown entity: com.beans.Dept
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:107)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1580)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1503)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
at com.test.Test.main(Test.java:17)
当我在 Dept.java 类上添加 @Entity 注释时,我得到了堆栈跟踪下方
Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: com.beans.Employee column: deptno (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:676)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:698)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:720)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:474)
at org.hibernate.mapping.RootClass.validate(RootClass.java:235)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1362)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865)
at com.test.Test.main(Test.java:17)
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<mapping class="com.beans.Employee"></mapping>
<mapping class="com.beans.Dept"></mapping>
</session-factory>
</hibernate-configuration>
package com.beans;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class Dept {
@Id
private int deptno;
private String dname;
private String loc;
@OneToMany(mappedBy = "dept")
Set<Employee> set;
public Set<Employee> getSet() {
return set;
}
public void setSet(Set<Employee> set) {
this.set = set;
}
public int getDeptno() {
return deptno;
}
public void setDeptno(int deptno) {
this.deptno = deptno;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
public String getLoc() {
return loc;
}
public void setLoc(String loc) {
this.loc = loc;
}
}
package com.beans;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "employee1")
public class Employee {
@Id
private int empno;
private String userName;
private int deptno;
@ManyToOne
@JoinColumn(name = "deptno")
private Dept dept;
public Dept getDept() {
return dept;
}
public void setDept(Dept dept) {
this.dept = dept;
}
public int getEmpno() {
return empno;
}
public void setEmpno(int empno) {
this.empno = empno;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getDeptno() {
return deptno;
}
public void setDeptno(int deptno) {
this.deptno = deptno;
}
}
package com.test;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.beans.Dept;
import com.beans.Employee;
public class Test {
public static void main(String[] args) {
Configuration configuration = new Configuration().configure();
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Employee employee = new Employee();
Dept dept = new Dept();
Set<Employee> set = new HashSet<Employee>();
set.add(employee);
dept.setDeptno(11);
dept.setDname("mca");
dept.setLoc("sbp");
dept.setSet(set);
session.save(dept);
employee.setEmpno(1);
employee.setUserName("rajeev");
employee.setDept(dept);
session.save(employee);
transaction.commit();
session.close();
}
}
谁能帮我找出错误...下面是github链接
git@github.com:mcarajeev/hibernate3.git
最佳答案
在 Employee.java 中,您已添加 deptno
作为连接列,并且已添加 deptno
作为列,因此它创建了两个 deptno
> 在同一个表中给出异常。
解决方案:您可以从 Employee.java 中删除 private int deptno
,因为您的 Join 列将用作外键。
关于java - 线程中的异常 "main"org.hibernate.AnnotationException : @OneToOne or @ManyToOne,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25793215/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!