整合是Struts 2.1.6 + Spring 2.5.6 + Hibernate 3.3.1
首先是数据库表/*==============================================================*/
/* Table: agents 代理 */
/*==============================================================*/
create table agents
(
agID int not null auto_increment,
agName varchar(30) not null,
agCompany varchar(100),
agLocation varchar(255),
agRes varchar(255),
primary key (agID)
);
/*==============================================================*/
/* Table: basicaInfo 基本信息 */
/*==============================================================*/
create table basicaInfo
(
biID int not null auto_increment,
meID int,
positionsID int,
atitleID int,
isMember bool,
intnWorkr int,
intnAgents int, --对应的代理编号--
meLocation int,
primary key (biID)
); CONSTRAINT `FK_Reference_22` FOREIGN KEY (`intnAgents`) REFERENCES `agents` (`agID`),
/*==============================================================*/
/* Table: agentsClass 课程 */
/*==============================================================*/
create table agentsClass
(
acID int not null auto_increment,
agentsID int not null,
classID int not null,
primary key (acID)
);Agents.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 package="net.cnyun.agents.entity">
<class name="Agents" table="agents">
<id name="agId" type="java.lang.Integer">
<column name="agID"/>
<generator class="native"/>
</id>
<property generated="never" lazy="false" name="agName" type="java.lang.String">
<column length="30" name="agName" not-null="true"/>
</property>
<property generated="never" lazy="false" name="agCompany" type="java.lang.String">
<column length="100" name="agCompany"/>
</property>
<property generated="never" lazy="false" name="agLocation" type="java.lang.String">
<column name="agLocation"/>
</property>
<property generated="never" lazy="false" name="agRes" type="java.lang.String">
<column name="agRes"/>
</property>
<set inverse="true" name="basicainfos" sort="unsorted">
<key>
<column name="intnAgents"/>
</key>
<one-to-many class="net.cnyun.member.entity.Basicainfo"/>
</set>
<set inverse="true" name="agpaies" sort="unsorted">
<key>
<column name="agID" not-null="true"/>
</key>
<one-to-many class="Agpay"/>
</set>
<set inverse="true" name="agentsclasses" sort="unsorted">
<key>
<column name="agentsID" not-null="true"/>
</key>
<one-to-many class="net.cnyun.clazz.entity.Agentsclass"/>
</set>
</class>
</hibernate-mapping>applicationContext.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true"> <bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/oasys</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--添加实体bean的xml-->
<property name="mappingLocations">
<value>classpath:/net/cnyun/**/**.hbm.xml</value>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/net/cnyun/**/entity</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.show_sql=true hibernate.format_sql=true
hibernate.query.substitutions=true 1, false 0
hibernate.connection.SetBigStringTryClob=true
hibernate.jdbc.batch_size=20
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.provider_configuration_file_resource_path=/ehcache-hibernate.xml
hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
</value>
</property>
</bean> <!-- 事务配置 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="net.cnyun" /> <!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="txManager" />
</beans>一贴发不下,错误信息在2楼
首先是数据库表/*==============================================================*/
/* Table: agents 代理 */
/*==============================================================*/
create table agents
(
agID int not null auto_increment,
agName varchar(30) not null,
agCompany varchar(100),
agLocation varchar(255),
agRes varchar(255),
primary key (agID)
);
/*==============================================================*/
/* Table: basicaInfo 基本信息 */
/*==============================================================*/
create table basicaInfo
(
biID int not null auto_increment,
meID int,
positionsID int,
atitleID int,
isMember bool,
intnWorkr int,
intnAgents int, --对应的代理编号--
meLocation int,
primary key (biID)
); CONSTRAINT `FK_Reference_22` FOREIGN KEY (`intnAgents`) REFERENCES `agents` (`agID`),
/*==============================================================*/
/* Table: agentsClass 课程 */
/*==============================================================*/
create table agentsClass
(
acID int not null auto_increment,
agentsID int not null,
classID int not null,
primary key (acID)
);Agents.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 package="net.cnyun.agents.entity">
<class name="Agents" table="agents">
<id name="agId" type="java.lang.Integer">
<column name="agID"/>
<generator class="native"/>
</id>
<property generated="never" lazy="false" name="agName" type="java.lang.String">
<column length="30" name="agName" not-null="true"/>
</property>
<property generated="never" lazy="false" name="agCompany" type="java.lang.String">
<column length="100" name="agCompany"/>
</property>
<property generated="never" lazy="false" name="agLocation" type="java.lang.String">
<column name="agLocation"/>
</property>
<property generated="never" lazy="false" name="agRes" type="java.lang.String">
<column name="agRes"/>
</property>
<set inverse="true" name="basicainfos" sort="unsorted">
<key>
<column name="intnAgents"/>
</key>
<one-to-many class="net.cnyun.member.entity.Basicainfo"/>
</set>
<set inverse="true" name="agpaies" sort="unsorted">
<key>
<column name="agID" not-null="true"/>
</key>
<one-to-many class="Agpay"/>
</set>
<set inverse="true" name="agentsclasses" sort="unsorted">
<key>
<column name="agentsID" not-null="true"/>
</key>
<one-to-many class="net.cnyun.clazz.entity.Agentsclass"/>
</set>
</class>
</hibernate-mapping>applicationContext.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true"> <bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/oasys</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--添加实体bean的xml-->
<property name="mappingLocations">
<value>classpath:/net/cnyun/**/**.hbm.xml</value>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/net/cnyun/**/entity</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.show_sql=true hibernate.format_sql=true
hibernate.query.substitutions=true 1, false 0
hibernate.connection.SetBigStringTryClob=true
hibernate.jdbc.batch_size=20
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.provider_configuration_file_resource_path=/ehcache-hibernate.xml
hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
</value>
</property>
</bean> <!-- 事务配置 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="net.cnyun" /> <!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="txManager" />
</beans>一贴发不下,错误信息在2楼
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from file C:\Tomcat6\webapps\OASYSTEM\WEB-INF\classes\net\cnyun\agents\entity\Agents.hbm.xml
at org.hibernate.cfg.Configuration.addFile(Configuration.java:352)
at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:695)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:666)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 65 more
Caused by: org.hibernate.DuplicateMappingException: Duplicate collection role mapping net.cnyun.agents.entity.Agents.basicainfos
at org.hibernate.cfg.Mappings.addCollection(Mappings.java:147)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2085)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2060)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:381)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:702)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:342)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from file C:\Tomcat6\webapps\OASYSTEM\WEB-INF\classes\net\cnyun\agents\entity\Agents.hbm.xml
大家帮我看看地址在
http://blog.csdn.net/soyestrellafortuna/archive/2009/08/21/4469541.aspx谢谢
这个文件有问题Duplicate collection role mapping net.cnyun.agents.entity.Agents.basicainfos
这个属性有问题!
您是指的Agents.hbm.xml文件吗?这个文件我贴在1楼了。Agents.java就是标准生成的bean文件
<key>
<column name="intnAgents"/>
</key>
<one-to-many class="net.cnyun.member.entity.Basicainfo"/>
</set>
配置有问题~把你的Agents实体类发出来看看。还有你的hbm如果是自动生成的。那就是你POJO问题了~
Agents.javapackage net.cnyun.agents.entity;import java.util.HashSet;
import java.util.Set;/**
* Agents entity.
*
* @author MyEclipse Persistence Tools
*/public class Agents implements java.io.Serializable { // Fields private Integer agId;
private String agName;
private String agCompany;
private String agLocation;
private String agRes;
private Set basicainfos = new HashSet(0);
private Set agpaies = new HashSet(0);
private Set agentsclasses = new HashSet(0); // Constructors /** default constructor */
public Agents() {
} /** minimal constructor */
public Agents(String agName) {
this.agName = agName;
} /** full constructor */
public Agents(String agName, String agCompany, String agLocation,
String agRes, Set basicainfos, Set agpaies, Set agentsclasses) {
this.agName = agName;
this.agCompany = agCompany;
this.agLocation = agLocation;
this.agRes = agRes;
this.basicainfos = basicainfos;
this.agpaies = agpaies;
this.agentsclasses = agentsclasses;
} // Property accessors public Integer getAgId() {
return this.agId;
} public void setAgId(Integer agId) {
this.agId = agId;
} public String getAgName() {
return this.agName;
} public void setAgName(String agName) {
this.agName = agName;
} public String getAgCompany() {
return this.agCompany;
} public void setAgCompany(String agCompany) {
this.agCompany = agCompany;
} public String getAgLocation() {
return this.agLocation;
} public void setAgLocation(String agLocation) {
this.agLocation = agLocation;
} public String getAgRes() {
return this.agRes;
} public void setAgRes(String agRes) {
this.agRes = agRes;
} public Set getBasicainfos() {
return this.basicainfos;
} public void setBasicainfos(Set basicainfos) {
this.basicainfos = basicainfos;
} public Set getAgpaies() {
return this.agpaies;
} public void setAgpaies(Set agpaies) {
this.agpaies = agpaies;
} public Set getAgentsclasses() {
return this.agentsclasses;
} public void setAgentsclasses(Set agentsclasses) {
this.agentsclasses = agentsclasses;
}}
<column name="intnAgents"/>
</key>
<one-to-many class="net.cnyun.member.entity.Basicainfo"/>
检查数据库字段名是否是intnAgents
basicaininfo的包位置是否准确~
刚才系统维护,现在才能回复信息
我检查过了字段也都正常,位置也没错。还有什么原因能引起这个错误呢?jndi也没错。hbm文件头也换过。屏蔽了这个类,相关联的另一个类就报错。
证明是你这个映射文件找不到。
证明你引用映射文件出错了。路径看下是否正确。
<!--添加实体bean的xml-->
<property name="mappingLocations">
<value>classpath:/net/cnyun/**/**.hbm.xml</value>
</property>应该问题出在这里!
你仔细看下!
create table agents
(
agID int not null auto_increment,
agName varchar(30) not null,
agCompany varchar(100),
agLocation varchar(255),
agRes varchar(255),
primary key (agID)
);
里面根本没有intnAgents字段嘛~~