/**
* Hibernate object, attribute query table name, field name tool class
*
*/
Package com. cinwa. creditnet. Common;
Import java. util. iterator;
Import org. hibernate. cfg. configuration;
Import org. hibernate. Mapping. column;
Import org. hibernate. Mapping. persistentclass;
Import org. hibernate. Mapping. Property;
Import org. hibernate. Mapping. Table;
Public class hibernateparter {
Private Static configuration hibernateconf;
Private Static configuration gethibernateconf (){
If (hibernateconf = NULL ){
// Return new configuration (). Configure ();
Return new configuration ();
}
Return hibernateconf;
}
Private Static persistentclass getpersistentclass (class clazz ){
Synchronized (hibernateparter. Class ){
Persistentclass Pc = gethibernateconf (). getclassmapping (
Clazz. getname ());
If (Pc = NULL ){
Hibernateconf = gethibernateconf (). addclass (clazz );
PC = gethibernateconf (). getclassmapping (clazz. getname ());
}
Return PC;
}
}
/**
* Obtain the table name corresponding to the object.
* @ Param clazz entity class
* @ Return table name
*/
Public static string gettablename (class clazz ){
Return getpersistentclass (clazz). gettable (). getname ();
}
/**
* obtain the primary key field name of the table corresponding to the object
* @ Param clazz entity class
* @ return primary key field name
* /
Public static string getpkcolumnname (class clazz) {
Table = getpersistentclass (clazz ). gettable ();
return table. getprimarykey (). getcolumn (0 ). getname ();
}
/**
* using entity classes and attributes, obtain the table field name corresponding to the object class attribute
* @ Param clazz entity class
* @ Param propertyname attribute name
* @ return field name
*/
Public static string getcolumnname (class clazz, string propertyname) {
persistentclass = getpersistentclass (clazz);
Property = persistentclass. getproperty (propertyname);
iterator it = property. getcolumniterator ();
If (it. hasnext () {
column = (column) it. next ();
return column. getname ();
}< br> return NULL;
}< BR >}