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
    @GeneratedValue
    private 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();
        }
    }
}

 

1个回答

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.

[url]https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Web_Server/1.0/html-single/Hibernate_Annotations_Reference_Guide/index.html[/url]

需要字节码增强后才能使用
[url]https://community.jboss.org/thread/98334[/url]
[url]http://www.darkmi.com/man/SpringSide3/Hibernate.html[/url]

jinnianshilongnian
jinnianshilongnian 跟jar包没关系 需要工具的支持 如给你发的 人家是ant编译
7 年多之前 回复
linshouyi2010
linshouyi2010 请问一下如何增强字节码呢?需要什么jar包?
7 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐