Can hibernate scan packages to create SessionFactory automatically?

后端 未结 2 1663
有刺的猬
有刺的猬 2021-01-11 15:49

Can I configure Hibernate to scan packages automatically to create a SessionFactory from @Entity annotated beans ?

Currently I am using

2条回答
  •  迷失自我
    2021-01-11 16:54

     public static  ArrayList listfiles(String pckgname) {
           ArrayList classes=new ArrayList();
    try{
    
        // Get a File object for the package 
        File directory=null; 
        try { 
          directory=new File(Thread.currentThread().getContextClassLoader().getResource(pckgname.replace('.', '/')).getFile()); 
        } catch(NullPointerException x) { 
          System.out.println("Nullpointer");
          throw new ClassNotFoundException(pckgname+" does not appear to be a valid package"); 
        } 
        if(directory.exists()) { 
          // Get the list of the files contained in the package 
          String[] files=directory.list(); 
          for(int i=0; i

提交回复
热议问题