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.  [ 4 posts ] 
Author Message
 Post subject: Composite element mapping not working
PostPosted: Fri Nov 03, 2006 11:45 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
I am using hibernate 3.2. The mapping i am trying to get to work is

Code:
<set name="ipRanges" table="network_ranges" lazy="false">
         <key column="network" not-null="true"/>
         <composite-element class="IPRange">
            <property name="name"/>
            <property name="start" type="IPAddressType">
               <column name="start_value"/>
               <column name="start_ip"/>
            </property>
            <property name="end" type="IPAddressType">
               <column name="end_value"/>
               <column name="end_ip"/>
            </property>
         </composite-element>
      </set>


IPAddressType is a UserType. On start up hibernate complains that the element mapping has too many columns.

Code:
org.hibernate.MappingException: collection element mapping has wrong number of columns: com.mfuse.novo.provisioning.persistent.Network.ipRanges type: component[name,start,end]
   at org.hibernate.mapping.Collection.validate(Collection.java:277)
   at org.hibernate.mapping.Set.validate(Set.java:19)



I am confused. What is the problem with my mapping?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 12:29 pm 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
can you post the table structure and the mapping files


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 1:23 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
The table structure is

Code:
network_ranges table

id (int) PK
network (int) FK on networks table
start_value (bigint)
end_value (bigint)
start_ip (varchar)
end_ip (varchar)

networks table

id (int) PK
name (varchar)


And the mapping file is

Code:
<hibernate-mapping>
   <class name="Network" table="networks">
      <id name="id" type="integer">
         <generator class="native" />
      </id>
      <property name="name"/>
      <set name="ipRanges" table="network_ranges">
         <key column="network"/>
         <composite-element class="IPRange">
            <property name="name"/>
            <property name="start" type="IPAddressType">
               <column name="start_value"/>
               <column name="start_ip"/>
            </property>
            <property name="end" type="IPAddressType">
               <column name="end_value"/>
               <column name="end_ip"/>
            </property>
         </composite-element>
      </set>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Composite element mapping not working
PostPosted: Wed May 05, 2010 12:12 pm 
Newbie

Joined: Wed May 05, 2010 11:07 am
Posts: 1
Hi guys,
is this problem solved? I'm facing almost the same one. (Hibernate version 3.3.2.GA)

This is my DB-schema:
Image

... and my classes:
Code:
public class EntityAuditRecord {
    private Long id;
    private Set<Diff> changes;

    //  other relevant stuff here
}

public class Diff {
    private String propertyName;
    private Object oldValue;
    private Object newValue;

    // setters, getters and the rest stuff here
}

... and here's my mapping:
Code:
<hibernate-mapping>
    <class name="EntityAuditRecord" table="ENTITY_AUDIT">
        <!-- ID and the rest fields' mapping here -->

        <set name="changes" table="ENTITY_DIFF">
            <key column="ENTITY_AUDIT_ID" />
            <composite-element class="Diff">
                <property name="propertyName" column="PROPERTY" />
                <property name="oldValue" column="OLD_VALUE" />
                <property name="newValue" column="NEW_VALUE" />
            </composite-element>
        </set>
    </class>
</hibernate-mapping>


When I try to run it I get the following exception:
Quote:
Caused by: org.hibernate.MappingException: collection element mapping has wrong number of columns: com.idc.worldwide.keystones.service.core.audit.domain.EntityAuditRecord.changes type: component[propertyName,oldValue,newValue]
at org.hibernate.mapping.Collection.validate(Collection.java:302)
at org.hibernate.mapping.Set.validate(Set.java:42)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1153)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 56 more


Table ENTITY_DIFF contains 4 columns (1 foreign key and 3 simple properties) and all of them are mapped.
I don't want to create a separate entity for Diff class and map it as <one-to-many>. According to the Hibernate Reference my mapping supposes to be correct. (See the first example here http://docs.jboss.org/hibernate/core/3. ... ollections)

How can I make it working? Am I missing something?

Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.