下面列出了怎么用org.hibernate.cfg.Mappings的API类实例代码及写法,或者点击链接到github查看源代码。
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
super.afterConfigurationBuilt( mappings, dialect );
// Oracle and Postgres do not have year() functions, so we need to
// redefine the 'User.person.yob' formula
//
// consider temporary until we add the capability to define
// mapping foprmulas which can use dialect-registered functions...
PersistentClass user = mappings.getClass( User.class.getName() );
org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
Component component = ( Component ) personProperty.getValue();
Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
if ( yearFunction == null ) {
// the dialect not know to support a year() function, so rely on the
// ANSI SQL extract function
f.setFormula( "extract( year from dob )");
}
else {
List args = new ArrayList();
args.add( "dob" );
f.setFormula( yearFunction.render( args, null ) );
}
}
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
super.afterConfigurationBuilt( mappings, dialect );
Collection children = mappings.getCollection( Parent.class.getName() + ".children" );
Component childComponents = ( Component ) children.getElement();
Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next();
SQLFunction lengthFunction = ( SQLFunction ) dialect.getFunctions().get( "length" );
if ( lengthFunction != null ) {
ArrayList args = new ArrayList();
args.add( "bio" );
f.setFormula( lengthFunction.render( args, null ) );
}
}
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
}
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect);