The following code is the service layer which contains a map with some key value pairs.
{1=A, 2=B, 3=c, 4=D} I want to store this in oracle database using hibernate.I do this previously using Model class mapping but i want to do this mapping to this collection.
public class CollectionMapping {
public static void main(String[] args) {
LinkedHashMap map = new LinkedHashMap();
map.put(1, "A");
map.put(2, "B");
map.put(3, "c");
map.put(4, "D");
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(map);
session.getTransaction().commit();
}
}
The following is hibernate config file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">Oracle Driver</property>
<property name="connection.url">URL</property>
<property name="connection.username">UserName</property>
<property name="connection.password">PassWord</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
this mapping class is for model class but how to do mapping for above collections
// <mapping class="org.symp.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>