我数据库里三张表 video document relatedocvideo 关系是document里可以有多个视频 通过关联表relatedocvideo进行关联的,videoId和documentId为主键,作为relatedocvideo里的外键。然后我用myeclipse的db browser生成的hibernate类和xml具体如下
hbm.xml文件
<hibernate-mapping>
    <class name="com.portal.model.CmsRelatedocvideo" table="cms_relatedocvideo">
        <composite-id name="id" class="com.portal.model.CmsRelatedocvideoId">
            <key-property name="documentId" type="java.lang.Integer">
                <column name="DocumentID" />
            </key-property>
            <key-property name="relateVideoId" type="java.lang.Integer">
                <column name="RelateVideoID" />
            </key-property>
            <key-property name="orders" type="java.lang.Short">
                <column name="Orders" />
            </key-property>
            <key-property name="playType" type="java.lang.Short">
                <column name="PlayType" />
            </key-property>
        </composite-id>
        <many-to-one name="CmsDocument" class="com.portal.model.CmsDocument" update="false" insert="false" fetch="select">
            <column name="DocumentID" not-null="true" />
        </many-to-one>
        <many-to-one name="CmsVideo" class="com.portal.model.CmsVideo" update="false" insert="false" fetch="select">
            <column name="RelateVideoID" not-null="true" />
        </many-to-one>
    </class>
</hibernate-mapping>
db browser生成了两个类
public class CmsRelatedocvideo  implements java.io.Serializable {
    // Fields         private CmsRelatedocvideoId id;
     private CmsDocument CmsDocument;
     private CmsVideo CmsVideo;
    // Constructors    /** default constructor */
    public CmsRelatedocvideo() {
    }    
    /** full constructor */
    public CmsRelatedocvideo(CmsRelatedocvideoId id, CmsDocument CmsDocument, CmsVideo CmsVideo) {
        this.id = id;
        this.CmsDocument = CmsDocument;
        this.CmsVideo = CmsVideo;
    }   
    // Property accessors    public CmsRelatedocvideoId getId() {
        return this.id;
    }
    
    public void setId(CmsRelatedocvideoId id) {
        this.id = id;
    }    public CmsDocument getCmsDocument() {
        return this.CmsDocument;
    }
    
    public void setCmsDocument(CmsDocument CmsDocument) {
        this.CmsDocument = CmsDocument;
    }    public CmsVideo getCmsVideo() {
        return this.CmsVideo;
    }
    
    public void setCmsVideo(CmsVideo CmsVideo) {
        this.CmsVideo = CmsVideo;
    }
package com.portal.model;/**
 * CmsRelatedocvideoId entity.
 * 
 * @author MyEclipse Persistence Tools
 */public class CmsRelatedocvideoId implements java.io.Serializable { // Fields private Integer documentId;
private Integer relateVideoId;
private Short orders;
private Short playType; // Constructors /** default constructor */
public CmsRelatedocvideoId() {
} /** minimal constructor */
public CmsRelatedocvideoId(Integer documentId, Integer relateVideoId,
Short playType) {
this.documentId = documentId;
this.relateVideoId = relateVideoId;
this.playType = playType;
} /** full constructor */
public CmsRelatedocvideoId(Integer documentId, Integer relateVideoId,
Short orders, Short playType) {
this.documentId = documentId;
this.relateVideoId = relateVideoId;
this.orders = orders;
this.playType = playType;
} // Property accessors public Integer getDocumentId() {
return this.documentId;
} public void setDocumentId(Integer documentId) {
this.documentId = documentId;
} public Integer getRelateVideoId() {
return this.relateVideoId;
} public void setRelateVideoId(Integer relateVideoId) {
this.relateVideoId = relateVideoId;
} public Short getOrders() {
return this.orders;
} public void setOrders(Short orders) {
this.orders = orders;
} public Short getPlayType() {
return this.playType;
} public void setPlayType(Short playType) {
this.playType = playType;
} public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof CmsRelatedocvideoId))
return false;
CmsRelatedocvideoId castOther = (CmsRelatedocvideoId) other; return ((this.getDocumentId() == castOther.getDocumentId()) || (this
.getDocumentId() != null
&& castOther.getDocumentId() != null && this.getDocumentId()
.equals(castOther.getDocumentId())))
&& ((this.getRelateVideoId() == castOther.getRelateVideoId()) || (this
.getRelateVideoId() != null
&& castOther.getRelateVideoId() != null && this
.getRelateVideoId()
.equals(castOther.getRelateVideoId())))
&& ((this.getOrders() == castOther.getOrders()) || (this
.getOrders() != null
&& castOther.getOrders() != null && this.getOrders()
.equals(castOther.getOrders())))
&& ((this.getPlayType() == castOther.getPlayType()) || (this
.getPlayType() != null
&& castOther.getPlayType() != null && this
.getPlayType().equals(castOther.getPlayType())));
} public int hashCode() {
int result = 17; result = 37
* result
+ (getDocumentId() == null ? 0 : this.getDocumentId()
.hashCode());
result = 37
* result
+ (getRelateVideoId() == null ? 0 : this.getRelateVideoId()
.hashCode());
result = 37 * result
+ (getOrders() == null ? 0 : this.getOrders().hashCode());
result = 37 * result
+ (getPlayType() == null ? 0 : this.getPlayType().hashCode());
return result;
}}我的ACTION里测试的
List list = relateDocVideoService.getRelateVideoByBundleId(Integer.valueOf(id).intValue());
System.out.println("绑定记录集长度==========="+list.size());
有记录
查询语句
public List getRelateVideoByBundleId(Integer documentid){
return this.getHibernateTemplate().find("from CmsRelatedocvideo where documentId="+documentid);
}for(int i = 0; i < list.size(); i++){
CmsRelatedocvideo dvvo = new CmsRelatedocvideo();
CmsRelatedocvideoId dvid = new CmsRelatedocvideoId();
dvvo = (CmsRelatedocvideo)list.get(i);
System.out.println(dvvo);
}
但是我测试打印对象为NULL

解决方案 »

  1.   

    org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Bean with name 'transactionManager' has been injected into other beans [transactionInterceptor] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
      

  2.   

    提示BEAN循环注入了,检查一下是不是BEAN间有相互注入的情形发生?