-->
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: Mapping a hashmap of objects
PostPosted: Sat May 12, 2007 10:41 am 
Newbie

Joined: Sat May 12, 2007 10:33 am
Posts: 1
Hi, I'm trying to map a HashMap into my database but cannot find the right way to do it. I have a "Gallery" class who has a HashMap collection of Pictures. But when I use the attached mapping document I get this exception:

Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: Picture column: picture_id (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
   at HibernateUtil.<clinit>(HibernateUtil.java:11)
   ... 36 more


Hibernate version:3.2.3

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <!-- Map the Gallery class -->
    <class name="Gallery" table="gallery">
        <!-- Auto-generate the Gallery ID -->
        <id name="gallery_id" column="gallery_id" type="integer">
            <generator class="increment"/>
        </id>
        <!-- Title of the gallery -->
        <property name="title" column="title" type="string"/>
        <!-- Description of the gallery -->
        <property name="description" column="description" type="string"/>
        <!-- Date of the gallery -->
        <property name="date" column="date" type="string"/>
        <!-- Map the pictures -->
        <map name="pictures">
            <key column="gallery_id" not-null="true"/>
            <map-key column="picture_id" type="integer"/>
            <one-to-many class="Picture" />
        </map>
    </class>
                                                                                               
    <!-- Map the Picture class -->
    <class name="Picture" table="picture">
        <!-- Auto-generate the Gallery ID -->
        <id name="picture_id" column="picture_id" type="integer">
            <generator class="increment"/>
        </id>
        <!-- Title of the gallery -->
        <property name="title" column="title" type="string"/>
        <!-- Description of the gallery -->
        <property name="description" column="description" type="string"/>
        <!-- Date of the gallery -->
        <property name="date" column="date" type="string"/>
        <!-- Width of the picture -->
        <property name="width" column="width" type="integer"/>
        <!-- Height of the picture -->
        <property name="height" column="height" type="integer"/>
        <!-- Binary data representation of the picture -->
        <property name="bytes" column="bytes" type="binary"/>
        <!-- Binary data representation of the thumbnail -->
        <property name="thumbnailAsBytes" column="thumbnail" type="binary"/>
        <!-- Foreign key which is mapping to the gallery ID that this picture belongs to -->
        <many-to-one name="gallery" column="gallery_id" class="Gallery" update="false" insert="false"/>
    </class>
</hibernate-mapping>


Thanks for helping me out :-)

regards


Top
 Profile  
 
 Post subject: Mapping a hashmap of objects
PostPosted: Sat May 12, 2007 7:17 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
Hello peltokew, i want to now what you're planning to use to be the keys of the map that you're trying to map, it seens to me that you're mapping something like this Map<Integer,Pictures> using the id of the pictures as a key of the map, it's that you what you want? if so, i could solve it by removing the not-null="true" in the gallery side and instead i used the not-null="true" on the picture side. Below are the resulting mapping, good luck.

Regards

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="test">

   <!-- Map the Gallery class -->
   <class name="Gallery" table="gallery">
      <!-- Auto-generate the Gallery ID -->
      <id name="gallery_id" column="gallery_id" type="integer">
         <generator class="increment" />
      </id>
      <!-- Title of the gallery -->
      <property name="title" column="title" type="string" />
      <!-- Description of the gallery -->
      <property name="description" column="description" type="string" />
      <!-- Date of the gallery -->
      <property name="date" column="date" type="string" />
      <!-- Map the pictures -->
      <map name="pictures">
         <key column="gallery_id"/>
         <map-key type="integer" column="picture_id"/>
         <one-to-many class="Picture" />
      </map>
   </class>

   <!-- Map the Picture class -->
   <class name="Picture" table="picture">
      <!-- Auto-generate the Gallery ID -->
      <id name="picture_id" column="picture_id" type="integer">
         <generator class="increment" />
      </id>
      <!-- Title of the gallery -->
      <property name="title" column="title" type="string" />
      <!-- Description of the gallery -->
      <property name="description" column="description" type="string" />
      <!-- Date of the gallery -->
      <property name="date" column="date" type="string" />
      <!-- Width of the picture -->
      <property name="width" column="width" type="integer" />
      <!-- Height of the picture -->
      <property name="height" column="height" type="integer" />
      <!-- Binary data representation of the picture -->
      <property name="bytes" column="bytes" type="binary" />
      <!-- Binary data representation of the thumbnail -->
      <property name="thumbnailAsBytes" column="thumbnail"
         type="binary" />
      <!-- Foreign key which is mapping to the gallery ID that this picture belongs to -->
      <many-to-one name="gallery" column="gallery_id" class="Gallery"/>
   </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.