Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.2
HashMap has been tranformed to TableDescription
(sorry for my bad english)
followed code all from hibernate3.2 src
for readable i changed the order of methods
----------------------------------------------------------------------------
public class Mappings implements Serializable {
Mappings(
.
.
final Map tableNamebinding,
..
){
this.tableNameBinding = tableNamebinding;
}
public void addTableBinding(
String schema, String catalog, String logicalName, String physicalName, Table denormalizedSuperTable
) {
String key = buildTableNameKey( schema, catalog, physicalName );
TableDescription tableDescription = new TableDescription(
logicalName, denormalizedSuperTable
);
//followed code are error code i think
TableDescription oldDescriptor = (TableDescription) tableNameBinding.put( key, tableDescription );//here is my question tableNameBinding is HashMap but TableDescription is a inner class
if ( oldDescriptor != null && ! oldDescriptor.logicalName.equals( logicalName ) ) {
//TODO possibly relax that
throw new MappingException("Same physical table name reference several logical table names: "
+ physicalName + " => " + "'" + oldDescriptor.logicalName + "' and '" + logicalName + "'");//should throw ClassCastException
}
}
static public class TableDescription implements Serializable {
public TableDescription(String logicalName, Table denormalizedSupertable) {
this.logicalName = logicalName;
this.denormalizedSupertable = denormalizedSupertable;
}
public String logicalName;
public Table denormalizedSupertable;
}
}
public class Configuration implements Serializable {
protected Map tableNameBinding;
protected void reset() {
..
tableNameBinding = new HashMap();
..
}
public Mappings createMappings() {
return new Mappings(
....
tableNameBinding,
columnNameBindingPerTable
);
}
public Configuration() {
this( new SettingsFactory() );
}
protected Configuration(SettingsFactory settingsFactory) {
this.settingsFactory = settingsFactory;
reset();
}
public Configuration configure(String resource) throws HibernateException {
..
return doConfigure( stream, resource );// doConfigure(Stream stream, String resource )
}
protected Configuration doConfigure(InputStream stream, String resourceName) throws HibernateException {
..
return doConfigure( doc );//doConfigure(Document doc )
}
protected Configuration doConfigure(org.dom4j.Document doc) throws HibernateException {
..
parseSessionFactory( sfNode, name );//parseSessionFactory( Element sfNode, String name );
..
}
private void parseSessionFactory(Element sfNode, String name) {
..
if ( "mapping".equals( subelementName ) ) {
parseMappingElement( subelement, name );//parseMappingElement(Element subelement, String name);
}
..
}
protected void parseMappingElement(Element subelement, String name) {
..
if ( rsrc != null ) {
log.debug( name + "<-" + rsrc );
addResource( rsrc.getValue() ); // addResource( String rsrc.getValue() );
}
..
}
public Configuration addResource(String resourceName) throws MappingException {
..
try {
return addInputStream( rsrc );//addInputStream( InputStream rsrc )
}
..
}
public Configuration addInputStream(InputStream xmlInputStream) throws MappingException {
..
add( doc );//add(Document)
..
}
protected void add(org.dom4j.Document doc) throws MappingException {
HbmBinder.bindRoot( doc, createMappings(), CollectionHelper.EMPTY_MAP );//
}
}