package com.data.beans;import java.util.Set;public class Type {
private int id;
private String name;
private String path;
private Set<Information> informations;
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPath() {
return path;
} public void setPath(String path) {
this.path = path;
} public Set<Information> getInformations() {
return informations;
} public void setInformations(Set<Information> informations) {
this.informations = informations;
}
}
<?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 package="com.data.beans">
<class name="Information" table="information">
<id column="id" name="id">
<generator class="identity"/>
</id>
<property column="name" generated="never" lazy="false" name="name"/>
<property column="path" generated="never" lazy="false" name="path"/>
<many-to-one class="com.data.beans.Type" fetch="select" name="type" lazy="false">
<column name="typeId"/>
</many-to-one>
</class>
</hibernate-mapping>
package com.data.beans;import java.util.Set;public class Type {
private int id;
private String name;
private String path;
private Set<Information> informations;
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPath() {
return path;
} public void setPath(String path) {
this.path = path;
} public Set<Information> getInformations() {
return informations;
} public void setInformations(Set<Information> informations) {
this.informations = informations;
}
}
<?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 package="com.data.beans">
<class name="Type" table="type">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name"/>
<property name="path" column="path"/>
<set name="informations" inverse="true" lazy="false">
<key>
<column name="id" />
</key>
<one-to-many class="com.data.beans.Information"/>
</set>
</class>
</hibernate-mapping>
异常
java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:796)
at java.util.HashMap$KeyIterator.next(HashMap.java:828)
at org.hibernate.collection.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:577)
at TypeTest.testFindById(TypeTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
private int id;
private String name;
private String path;
private Set<Information> informations;
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPath() {
return path;
} public void setPath(String path) {
this.path = path;
} public Set<Information> getInformations() {
return informations;
} public void setInformations(Set<Information> informations) {
this.informations = informations;
}
}
<?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 package="com.data.beans">
<class name="Information" table="information">
<id column="id" name="id">
<generator class="identity"/>
</id>
<property column="name" generated="never" lazy="false" name="name"/>
<property column="path" generated="never" lazy="false" name="path"/>
<many-to-one class="com.data.beans.Type" fetch="select" name="type" lazy="false">
<column name="typeId"/>
</many-to-one>
</class>
</hibernate-mapping>
package com.data.beans;import java.util.Set;public class Type {
private int id;
private String name;
private String path;
private Set<Information> informations;
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPath() {
return path;
} public void setPath(String path) {
this.path = path;
} public Set<Information> getInformations() {
return informations;
} public void setInformations(Set<Information> informations) {
this.informations = informations;
}
}
<?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 package="com.data.beans">
<class name="Type" table="type">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name"/>
<property name="path" column="path"/>
<set name="informations" inverse="true" lazy="false">
<key>
<column name="id" />
</key>
<one-to-many class="com.data.beans.Information"/>
</set>
</class>
</hibernate-mapping>
异常
java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:796)
at java.util.HashMap$KeyIterator.next(HashMap.java:828)
at org.hibernate.collection.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:577)
at TypeTest.testFindById(TypeTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
解决方案 »
- Hibernate中使用annotation问题
- com.microsoft.sqlserver.jdbc.SQLServerException: 该语句没有返回结果集。
- JSF 如何获得客户机IP?
- Struts初始化的问题!
- weblogic如何配置单点登录(sso)呀?
- 纵横网络这么多天,也没找到,特来求救
- struts问题
- 请教!!!
- 请问applet中怎样处理线程
- 有没有试过从javabean到xml的过程阿,这样要实现的话javabean要有什么条件才可以转化成xml?
- 求Struts2.3.4校验框架实现ajax客户端输入合法性校验的教程
- 急求指导!一个关于hashmap的containKey方法的错误。
//这里的name就是你的外键(我一般这样写),column就是将来跟部门表做关联用的。上面是员工表配置。
下面是部门表配置。<set name="emps">
<key column="department_id" />
<one-to-many class="com.le.domain.Employee" />
</set>
//这里的name随便给一个就行了,但是key必须是员工表的many-to-one的column,必须一样。而且不推荐你用关键字,就是type,type在数据库和java中都是关键字吧?所以用一个别的代替,哪怕加一个下划线啊