0

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>
Rajasekhar
  • 787
  • 6
  • 13
  • 31
  • 1
    Are you asking how to map a Map collection in hibernate? If so - http://stackoverflow.com/questions/2327971/how-do-you-map-a-map-in-hibernate-using-annotations – Andy Dufresne Dec 11 '14 at 05:11

1 Answers1

1

I'm not sure what your database schema that you are trying to map to looks like, but this should help: https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/collections.html

JRoc
  • 21
  • 2