-->
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: Problem while using Map Object in Hibernate
PostPosted: Thu Mar 23, 2006 10:13 am 
Newbie

Joined: Thu Mar 23, 2006 10:06 am
Posts: 1
Hi All,

I am facing problem while using Map Object in Hibernate.
I have following 3 tables:

mysql> desc DefaultPropertyAV;
+--------------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+------------------+------+-----+---------+----------------+
| defaultPropertyAVKey | int(11) unsigned | NO | PRI | | auto_increment |
| userKey | int(11) unsigned | NO | MUL | | |
| defaultPropertyAttribKey | int(11) unsigned | NO | MUL | | |
| defaultPropertyValueKey | int(11) unsigned | NO | MUL | | |
+--------------------------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> desc DefaultPropertyAttrib;
+--------------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+------------------+------+-----+---------+----------------+
| defaultPropertyAttribKey | int(11) unsigned | NO | PRI | | auto_increment |
| attribName | varchar(255) | NO | | | |
+--------------------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> desc DefaultPropertyValue;
+-------------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+------------------+------+-----+---------+----------------+
| defaultPropertyValueKey | int(11) unsigned | NO | PRI | | auto_increment |
| VALUE | varchar(255) | NO | | | |
+-------------------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)


I need to add a map object in hbm file of DefaultPropertyAV table.
This map will contain key as "defaultPropertyAttribKey" of second table, and value as "defaultPropertyValueKey" of third table. But I am getting following exception while trying to run with above stuff:

org.hibernate.MappingException: Foreign key (FKC63599CB61F99016:DefaultPropertyAV [defaultPropertyAVKey])) must have same number of columns as the referenced primary key (DefaultPropertyAV [defaultPropertyAVKey,defaultPropertyAttribKey])

at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)

at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)

at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:976)

at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)

at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)

at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)

at ………..



IF ANYONE HAVE FACED SAME KIND OF PROBLEM, PLEASE GUIDE ME IF YOU HAVE ANY IDEA REGARDING THIS.

Thanks in Advance.

Regards,
Sachin Naik
India


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 9:54 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Why does this have to be a map? Given that the foreign keys in DefaultPropertyAV correspond to primary keys in the other two tables, it follows that one row in DefaultPropertyAV has one and only one Attrib, and one and only one Value. Why do you want to treat this as a map? The power in maps relates to their extensibility: one row in the owning table has a map of any number of items in the map table. This should be mapped as two many-to-one unique="true" mappings.

If you have a particular reason to return a map from the class that models DefaultPropertyAV, then you can create that in java from the two relevant entities in the DefaultPropertyAV object.

Is it that there's some other table that has a reference to DefaultPropertyAV, and the class that models that other table is the one you want to contain the Map?


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.