package com.dts.test;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Configuration conf = new AnnotationConfiguration();
ArrayList<Class> classes = new ArrayList<Class>();
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
for (BeanDefinition bd : scanner.findCandidateComponents("com.abc.model")) {
String name = bd.getBeanClassName();
try {
classes.add(Class.forName(name));
} catch (Exception E) {
}
}
for(Class one : classes) {
conf.addAnnotatedClass(one);
}
SessionFactory sf = conf.configure().buildSessionFactory();
Session session = sf.openSession();
try {
Query query = session.createQuery("from User t where t.state = :statetate");
query.setParameter("state", 1);
List list = query.list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
session.close();
}
}
}
分享到:
相关推荐
Thinking in Java 4th Edition Annotated Solutions Guide!
Thinking in Java 4th Edition 英文文字版,带书签 Annotated Solution Guide 有代码
这是《The Thinking in Java Annotated Solution Guide》的所有代码的压缩包。
Thinking in Java 4th Edition with Annotated Solution Guide 编程思想+课后习题指导+源码
thinking in java annotated solution guide.chm 电子书格式
Annotated Solution Guide for Thinking in Java 4th Edition 中文资源名称:Thinking In Java第四版 课后练习答案。这本是 herosongly 上传的,但是他要 10 分 的资源分,导致很多朋友不能下载。我现在将其免费公布...
Annotated Solution Guide for Thinking in Java 4th Edition(高清pdf) Thinking In Java第四版 课后练习答案
Java 编程思想第四版,章节练习题参考答案
低压配电柜培训资料~! - 低压开关柜基本知识简介 低压主要元件介绍 断路器与开关 低压中常用的可分为:万能式断路器;塑壳式断路器;微型断路器;刀熔开关;隔 离刀...
Thinking in Java Annotated Solution Guide(TIJ4-solutions)
Following this, you will explore how to implement the request handling layer using Spring annotated controllers. Other highlights include learning how to build the Java DAO implementation layer by ...
Following this, you will explore how to implement the request handling layer using Spring annotated controllers. Other highlights include learning how to build the Java DAO implementation layer by ...
The Thinking in java Annotated Solution Guide 是Thinking in Java 的习题答案,对于你学习Thinking in Java这本书有很大的帮助!
Annotated Solution Guide for Thinking in Java
次文档为 thingking in java 第四版的练习题答案
Thinking in Java Annotated Solutions Guide, Revision 1.0 - Contents Thinking in Java, 2nd edition, Annotated Solution Guide Revision 1.0 by Bruce Eckel ©2002 MindView, Inc. [ Table of Contents ] [ ...
The authors are all members of the Java EE 6 documentation team at Oracle. Eric Jendrock leads the Java EE Tutorial team and documents Java Servlet technology and Java security. Ian Evans documents ...
这是 《java编程思想》(think in java)的章节练习答案。 文件为 pdf 格式,英文版。