`
lzj0470
  • 浏览: 1244515 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

many-to-one lazy

 
阅读更多
// 删除配置文件(Books.hbm.xml)的标签(many-to-one)属性(lazy)的话,就不显示下面语句。原因不明
package com.hibernate.entity;

import java.io.Serializable;

public class Publishers implements Serializable {

	public int id;
	
	public String name;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
}

<?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>
	<class name="com.hibernate.entity.Publishers" table="publishers" catalog="bookshop">
		<id name="id" type="java.lang.Integer">
			<column name="Id" />
			<generator  class="native"></generator>
		</id>
		<property name="name" type="java.lang.String">
			<column name="Name" length="16" not-null="true" />
		</property>
		
	</class>
</hibernate-mapping>

<?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>
	<class name="com.hibernate.entity.Books" table="Books" catalog="bookshop">
		<id name="id" type="java.lang.Integer">
			<column name="Id" />
			<generator  class="native"></generator>
		</id>
		<property name="title" type="java.lang.String">
			<column name="title" length="16" not-null="true"></column>
		</property>
		<many-to-one name="Publishers" column="PublisherId" class="com.hibernate.entity.Publishers"></many-to-one>
	</class>
</hibernate-mapping>

package com.hibernate.entity;

import java.io.Serializable;

public class Books implements Serializable {
	
	private int id;
	
	private Publishers publishers;

	public Books(){}

	public Publishers getPublishers() {
		return publishers;
	}

	public void setPublishers(Publishers publishers) {
		this.publishers = publishers;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	
}

package com;

import org.junit.Test;

import com.hibernate.dao.BaseHibernateDAO;
import com.hibernate.entity.Books;

public class Select extends BaseHibernateDAO {

	@Test
	public void select() {
		Books books = (Books) super.get(Books.class, 4939);
		// 删除配置文件(Books.hbm.xml)的标签(many-to-one)属性(lazy)的话,就不显示下面语句。原因不明 
		System.out.println("name=" + books.getPublishers().getName());
	}
	
}
分享到:
评论

相关推荐

    英语资料,很有用的哦

    &lt;many-to-one name="systemSpecialtyCode" class="com.hibernate.model.SystemSpecialtyCode" fetch="select" lazy="false"&gt; &lt;/many-to-one&gt; &lt;many-to-one name="systemGradeCode" class=...

    Lazy loading - eager loading

    &lt;one-to-many class="OrderLine"/&gt; &lt;/hibernate-mapping&gt;Analogous you can implement the mappings for the Customer entity &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:...

    Hibernate学习笔记

    020 &lt;one-to-one&gt;、&lt;many-to-one&gt;单端关联上的 lazy(懒加载)属性 021 继承关联映射 022 component(组件)关联映射 023 复合主键 关联映射 024 其它 关联映射 025 hibernate 悲观锁、乐观锁 026 hibernate 操作树形...

    Hibernate中文API大全

    &lt;many-to-one name="purchaseDetails" class="eg.Purchase"/&gt; &lt;many-to-one name="item" class="eg.Item"/&gt; &lt;/composite-element&gt; 在查询中,表达组合元素的语法和关联到其他实体的语法是一样的。 8.3. 组件...

    hibernate总结

    &lt;many-to-one name="dept" class="org.wllt.www.po.Dept" fetch="select" cascade ="none" lazy ="proxy"&gt; &lt;/many-to-one&gt; &lt;/property&gt; &lt;/hibernate-mapping&gt; Hibernate映射一对一...

    Hibernate Reference Documentation3.1

    7.5.1. one to many / many to one 7.5.2. one to one 7.5.3. many to many 7.6. More complex association mappings 8. Component Mapping 8.1. Dependent objects 8.2. Collections of dependent objects 8.3. ...

    NHibernate中文文档

    一对多关联(One-To-Many Associations) 14 延迟初始化(延迟加载)(Lazy Initialization) 14 集合排序(Sorted Collections) 14 使用 &lt;idbag&gt; 14 双向关联(Bidirectional Associations) 14 三重关联(Ternary ...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的关联映射 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) ...

    HibernateAPI中文版.chm

    7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的关联映射 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) ...

    hibernate3.2中文文档(chm格式)

    7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的关联映射 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) ...

    Hibernate中文详细学习文档

    7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many ...

    hibernate 体系结构与配置 参考文档(html)

    一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的关联映射 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在...

    Git-2.21.0-64-bit.zip

    * "git fetch" into a lazy clone forgot to fetch base objects that are necessary to complete delta in a thin packfile, which has been corrected. * The filter_data used in the list-objects-filter ...

    Hibernate+中文文档

    7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many ...

    Hibernate 中文 html 帮助文档

    7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的关联映射 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在...

    最全Hibernate 参考文档

    7.4.1. 一对多(one to many) / 多对一(many to one) 7.4.2. 一对一(one to one) 7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to ...

    Hibernate3+中文参考文档

    7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 8. 组件(Component)映射 8.1. 依赖对象(Dependent objects) 8.2. 在集合中出现的依赖对象 ...

    hibernate 框架详解

    一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖对象 ...

    [Go语言入门(含源码)] The Way to Go (with source code)

    The Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书中源代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface......................

    hibernate3.04中文文档.chm

    8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件(Component)映射 9.1. 依赖对象(Dependent objects) 9.2. 在集合中出现的依赖...

Global site tag (gtag.js) - Google Analytics