hibernate 关于 注解配置@Basic(fetch=FetchType.LAZY) 不起效果

问题描述

intro字段配置成@Basic(fetch=FetchType.LAZY) 但是无论用get还是load方法,intro和其他字段都是一样加载的,和其他字段没有区别啊?配了和没配是一样的?有没有人和我一样的问题啊,我用的是hibernate3.3 import java.util.Date;import javax.persistence.Basic;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.Table;import org.hibernate.Session;import org.hibernate.Transaction;import com.test.HibernateSessionFactory;@Entity//@Table(name="t_student",uniqueConstraints=@UniqueConstraint(columnNames={"name","sex"}))@Table(name="t_student")public class Student{@Id@GeneratedValueprivate Integer id;private String name;private Date birthday;private Boolean sex;private Integer age;private Double grade;@Basic(fetch=FetchType.LAZY)private String intro;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public Boolean getSex() {return sex;}public void setSex(Boolean sex) {this.sex = sex;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public Double getGrade() {return grade;}public void setGrade(Double grade) {this.grade = grade;}public String getIntro() {return intro;}public void setIntro(String intro) {this.intro = intro;}public static void main(String[] args) {Session session = HibernateSessionFactory.getSession();Transaction transaction = session.beginTransaction();transaction.begin();try{//School school = new School();//school.setName("清华大学");////school.setIntro("bca");//Student t = new Student();//t.setName("武林");//t.setAge(100);//t.setBirthday(new Date());//t.setSex(true);//t.setIntro("xx");//t.setGrade(59.99d);//t.setSchool(school);//session.save(t);Student t = (Student)session.load(Student.class, 1);String name = t.getName();String intro = t.getIntro();transaction.commit();}catch(Exception e){e.printStackTrace();transaction.rollback();}finally{session.close();}}}

解决方案

To enable property level lazy fetching, your classes have to be instrumented: bytecode is added to the original one to enable such feature, please refer to the Hibernate reference documentation. If your classes are not instrumented, property level lazy loading is silently ignored.https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Web_Server/1.0/html-single/Hibernate_Annotations_Reference_Guide/index.html需要字节码增强后才能使用https://community.jboss.org/thread/98334http://www.darkmi.com/man/SpringSide3/Hibernate.html

时间: 2024-07-29 14:11:18

hibernate 关于 注解配置@Basic(fetch=FetchType.LAZY) 不起效果的相关文章

hibernate5(4)实体映射注解配置[1]注解全面解析

相对于经典风格的实体配置xxx.hbm.xml,新版本hibernate使用JPA(Java Persistence API)注解配置能使我们的开发更加敏捷便利.在本系列前面部分的文章中,我们围绕JPA注解风格配置来逐步深入学习. 配置实例 下面先看一个实体类的配置实例: package com.zeng.model; import java.util.Date; import javax.persistence.Basic; import javax.persistence.Column; i

hibernate JPA 单表树形结构 注解配置。(已解决)

问题描述 ublic class Category implements java.io.Serializable { @Id @GeneratedValue(strategy=IDENTITY) @Column(name="CAT_ID", unique=true, nullable=false) private Integer id; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="CAT_PARENT_ID"

hibernate注解配置关联关系

1.在判断到底是谁维护关联关系时,可以通过查看外键,哪个实体类定义了外键,哪个类就负责维护关联关系. JoinColumn(name="pid") 2. 在保存数据时,总是先保存的是没有维护关联关系的那一方的数据,后保存维护了关联关系的那一方的数据,如:             Person p = new Person();             p.setName("xiaoluo");             session.save(p);        

hibernate 3 注解,sql2005 自增得不到主键值

问题描述 我使用的是Hibernate3+注解+SQL2005开发系统的.我的POJO是这样配置的"java"packagecom.chinaunicom.pt.domain.entity;importjava.util.Date;importjavax.persistence.*;importjavax.persistence.Entity;importjavax.persistence.FetchType;importjavax.persistence.GeneratedValue

spring hibernate 用注解生成表,怎么保存主从信息

问题描述 我用注解生成了3张表,DepartmentPersonnel还有一张中间表personnel_department我应该怎么保存信息呢? 解决方案 解决方案二:@Entity@Table(name="department")publicclassDepartment{privateintid;privateStringdepartname;privateSet<Personnel>set=newHashSet<Personnel>();//privat

ssh-SSH整合,hibernate注解配置,无hbm.xml,映射出现问题

问题描述 SSH整合,hibernate注解配置,无hbm.xml,映射出现问题 java实体类代码: package cn.com.car.base.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; i

hibernate5(5)实体映射注解配置[2]主键生成策略

@GeneratedValue基本注解类型 在上一篇文章中,我们讲到了JPA使用@GeneratedValue注解来定义生成策略,而关于注解生成策略有4种基本支持类型: 1. GenerationType.TABLES 当前主键的值单独保存到一个数据库的表中 2. GenerationType.SEQUENCE 利用底层数据库提供的序列生成标识符 3. GenerationType.IDENTITY 采取数据库的自增策略 4. GenerationType.AUTO 根据不同数据库自动选择合适的

spring注解配置以文本方式导出

问题描述 spring配置是基于注解的方式可不可把注解配置以xml或者文本格式导出以便方便测试和查错这个估计是要系统运行时候才能导出..还有hibernate的注解可不可以导出成为xml后者文本? 解决方案 解决方案二:注解还可以导出啊?学习了!解决方案三:不是很明白解决方案四:没听太明白?解决方案五:路过--

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->Maven Project--->Next(之后界面如下所示:) --->Next(点击next之后出现如下界面:选择最后一个 maven-archetype-webapp,然后点击next) --->Next(点击next之后出现如下界面,然后选择好组织号,工程号,版本号即可),最后点击Fi