In the Java object, I don't know that a good naming specification uses uppercase words, such as the order item, even the name of ORDERITEM, which is easy to see that this object is from ORDER and ITEM 2 If the word consists of words, it is easy, and the attribute is also the case, such as MaxPrice, Totalprice, and more. However, if the same naming specification is shipped to the database, because many database is not sensitive to the table name, the field name is not sensitive So the most common strategy is based on the basis of the line as a synonym: ORDERITEM -> ORDER_ITEM MAXPRICE -> MAX_PRICE When using Hibernate, you have to indicate in the mapping file:
Java code:
Import Net.
sf.
Hibernate.
CFG.
Namingstrategy;
Import Net.
sf.
Hibernate.
Util.
Stringhelper;
/ ** * An improved naming statate trying trying with us on defaultnamingstrategy and improvednamingstrategy * * /
public
Class undercorenamingstrategy
Implements namingstrategy
{
public
Static
Final namingstrategy instance =
New understandcorenamingstrategy
(
);
Protected undercorenamingstrategy
(
)
{
}
public
String classtotablename
(
String classname
)
{
Return Addunderscores
Stringhelper.
UNQUALIFY
(ClassName
)
);
}
public
String propertyTytocolumnname
(
String PropertyName
)
{
Return Addunderscores
Stringhelper.
UNQUALIFY
(PropertyName)
)
);
}
public
String Tablename
(
String Tablename
)
{
Return TableName;
}
public
String columnname
(
String columnname
)
{
Return columnname;
}
public
String PropertyTotableName
(
String ClassName,
String PropertyName
)
{
Return ClasstotableName
(ClassName
)
'_' PropertyToColumnName
(PropertyName)
);
}
Private
String Addunderscores
(
String name
)
{
StringBuffer buf =
New
StringBuffer
(Name.Replace
(
'.',
'_'
)
);
for
(
INT i =
1; i Length ( ) 1; i ) { IF ( '_'! = BUF. Charat (i - 1 ) && CHARACTER. iSuppercase (BUF. Charat (i ) ) &&! CHARACTER. iSuppercase (BUF. Charat (i 1 ) ) ) { BUF. insert (i , '_' ); } } Return BUF. Tostring ( ). TOLOWERCASE ( ); } } In the initialization configuration, add this NamingStrategy plus: Java code: Configuration config = New Configuration ( ); CONFIG. Setnamingstrategy Underscorenamingstrategy. Instance ); This mapping file has become more simple: