I am trying to create a schema using an hbm.xml file (which i plan to generate dynamically) where the entity mode is
dynamic-map, so the backing object is a HashMap.
I can do this to read from a table but Is what I am trying to do possible for creating a table?
Code:
<hibernate-mapping package="java.util">
<class name="HashMap" table="dyntest">
<id name="id">
<generator class="native"/>
</id>
<property name="amount"
scale="19"
precision="31" />
<property name="datetime"
column="createdDatetime"/>
</class>
</hibernate-mapping>
Code:
Configuration configuration = new Configuration();
configuration.setProperty( "hibernate.dialect", "org.hibernate.dialect.MySQLDialect" );
configuration.setProperty( "hibernate.default_entity_mode", "dynamic-map" );
configuration.setProperty( "hibernate.show_sql", "true" );
configuration.setProperty( "hibernate.connection.driver_class", "com.mysql.jdbc.Driver" );
configuration.setProperty( "hibernate.connection.url", "jdbc:mysql://localhost:3306/hibtest" );
configuration.setProperty( "hibernate.connection.username", "root" );
configuration.setProperty( "hibernate.connection.password", "iwtbde" );
configuration.addResource( "com/javamark/test/Test.hbm.xml" );
SchemaExport export = new SchemaExport(configuration);
export.execute( true, true, false, false );
it fails for obvious reasons:
used by: org.hibernate.PropertyNotFoundException: field [id] not found on java.util.HashMap
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:112)