如何将spring项目转换为spring boot项目?我在spring项目中有HQL查询

时间:2015-08-24 10:47:38

标签: java spring hibernate spring-boot hql

我想问你,我怎样才能将我的春季项目改为春季启动项目。我已经在spring中创建了一个项目并使用hql查询进行了hibernate现在我想将我的项目转换为spring boot。有什么办法,或者我必须再次编写代码。我有点困惑,我的DAO类代码将在spring boot项目中编写。

这是我的 DAO 类代码

@SuppressWarnings({ "unchecked" })
public List<User> getUsersWithSameProfessionsById(long id) throws Exception {
    session = sessionFactory.openSession();
    String queryString = "SELECT DISTINCT a FROM Profession p1, Profession p2, Address a JOIN p2.user u WHERE p1.u_id=:id AND p2.profession=p1.profession AND a.uid=u.id AND a.uid!=:id";
    Query query = session.createQuery(queryString);
    query.setLong("id", id);
    //query.setMaxResults(10);

    List<User> professionList = query.list();
    Set<User> foo = new HashSet<User>(query.list());

    List<User> professionList1 = null;
    Set<User> foo1 = new HashSet<User>();

    int a=10-professionList.size();
    Query query1=null;
    if(professionList.size()<10){

        String queryString1 = "SELECT DISTINCT a FROM Address c1, Address c2, Address a JOIN c2.user u WHERE c1.uid=:id AND c2.city=c1.city AND a.uid=u.id AND a.uid!=:id";
        query1 = session.createQuery(queryString1);
        query1.setLong("id", id);
        //query1.setMaxResults(a);

        foo1.addAll(query1.list());
        professionList1 = query1.list();

    }

    List<User> professionList2 = new ArrayList<User>();
    List<User> professionList3 = new ArrayList<User>();
    List<User> professionList4 = new ArrayList<User>();
    List<User> professionList5 = new ArrayList<User>();
    professionList2.addAll(professionList);
    professionList2.addAll(professionList1);
    Set<User> foo2 = new HashSet<User>();
    Set<User> foo5 = new HashSet<User>();
    foo2.addAll(foo);
    foo2.addAll(foo1);
    professionList3.addAll(foo2);


    int b=10-professionList3.size();
    Set<User> foo4 = new HashSet<User>();
    Query query2=null;
    if(professionList3.size()<10){

        String queryString2 = "SELECT DISTINCT a FROM Address c1, Address c2, Address a JOIN c2.user u WHERE c1.uid=:id AND c2.country=c1.country AND a.uid=u.id AND a.uid!=:id";
        query2 = session.createQuery(queryString2);
        query2.setLong("id", id);
        //query2.setMaxResults(b);

        foo4.addAll(query2.list());
        professionList4 = query2.list();

    }

    foo5.addAll(foo2);
    foo5.addAll(foo4);
    professionList5.addAll(foo5);

    return professionList5;
}   

请帮助我,我很困惑。

0 个答案:

没有答案