首页 > 代码库 > 通过hibernatesession取表名、字段等

通过hibernatesession取表名、字段等

 1  protected String getTableNameByClass(Class<?> T){ 2         AbstractEntityPersister cm = (AbstractEntityPersister) 3                 super.getHibernateSession().getSessionFactory().getClassMetadata(T); 4         if(null!=cm){ 5             return cm.getTableName().toLowerCase(); 6         } 7         return null; 8     } 9     protected Map<String,String> getColumnNameMap(Class<?> T){10         AbstractEntityPersister cm = (AbstractEntityPersister)11                 super.getHibernateSession().getSessionFactory().getClassMetadata(T);12         Map<String,String> map = new HashMap();13         if(null!=cm){14             String[] propertyNames = cm.getPropertyNames();15             for(int i = 0; i<propertyNames.length; i++){16                 String[] columnNames = cm.getPropertyColumnNames(propertyNames[i]);17                 if(null!=columnNames && columnNames.length>0){18                     map.put(propertyNames[i],columnNames[0]);19                 }20             }21         }22         return map;23     }

 

通过hibernatesession取表名、字段等