-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using dynamic-map to create schema
PostPosted: Thu Jul 26, 2007 1:43 pm 
Newbie

Joined: Wed Jul 25, 2007 4:10 pm
Posts: 4
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 6:47 pm 
Newbie

Joined: Wed Jul 25, 2007 4:10 pm
Posts: 4
Found the answer, by chance after running the hbm2java and learning that before you could generate the java POJO it wanted to find the class file for the same POJO ehh!!! **if and only if** you dont specify the hibernate types for the fields.

So I tried the following simple mapping, this time specifying all the types. hey presto it worked.

Code:
<hibernate-mapping >

   <class name="Point" table="Point">
      <id name="id" type="int">
         <generator class="native"/>
      </id>
      <property name="description" type="string" length="5" />
   </class>
   
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.