Hi all...
Even though this thread is more than 4 years old, I'm wondering whether somebody was able to get this programmatic mapping configuration working. I tried to reproduce what
kulkarnm had attempted, however, I had to change a few things since I'm using Hibernate 4.1. Unfortunately, even though the code is not bombing, it doesn't create anything at all in my database.
Code:
private void setup (Configuration p_Configuration, String p_TableName, String p_EntityName)
{
Dialect l_Dialect;
Column lIdentifierColumn;
Property l_IdentifierProperty;
SimpleValue l_IdentifierValue;
boolean l_AlreadyMapped = false;
Iterator <PersistentClass> l_ClassMappingsIterator;
PersistentClass l_ClassMapping;
m_Configuration = p_Configuration;
l_Dialect = Dialect.getDialect (m_Configuration.getProperties());
l_ClassMappingsIterator = m_Configuration.getClassMappings();
while (l_ClassMappingsIterator.hasNext() && !l_AlreadyMapped)
{
l_ClassMapping = l_ClassMappingsIterator.next();
l_AlreadyMapped = l_ClassMapping.getMappedClass().equals(this.getClass());
}
if (!l_AlreadyMapped)
{
m_Mappings = m_Configuration.createMappings();
m_Table = new Table (p_TableName);
l_IdentifierColumn = new Column (c_Identifier);
l_IdentifierColumn.setSqlType(l_Dialect.getTypeName(java.sql.Types.INTEGER));
l_IdentifierValue = new SimpleValue (m_Mappings,m_Table);
l_IdentifierValue.setTypeName ("int");
l_IdentifierValue.addColumn (l_IdentifierColumn);
l_IdentifierProperty = new Property();
l_IdentifierProperty.setName (c_Identifier);
l_IdentifierProperty.setValue (l_IdentifierValue);
l_IdentifierProperty.setGeneration (PropertyGeneration.INSERT);
m_Entity = new RootClass ();
m_Entity.setEntityPersisterClass (DynamicEntityBean.class);
m_Entity.setEntityName (p_EntityName);
m_Entity.setJpaEntityName (p_EntityName);
m_Entity.setTable(m_Table);
m_Entity.setIdentifier(l_IdentifierValue);
m_Entity.setIdentifierProperty(l_IdentifierProperty);
m_Mappings.addClass(m_Entity);
}
My hibernate.hbm2ddl.auto property in the hibernate.cfg.xml file is set to
update.
Any idea what I'm missing ?
Many thanks in advance...