-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping of a foreign key
PostPosted: Mon Mar 05, 2007 5:53 am 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:28 am
Posts: 22
Hi

I want to map a one-to-many association over a MySQL foreign key. But it throws a SQLGrammarException:

Code:
Hibernate: select categories0_.FK_SURVEYID as FK6_1_, categories0_.CATEGORYID as CATEGORYID1_, categ
ories0_.CATEGORYID as CATEGORYID5_0_, categories0_.CATEGORYNAME as CATEGORY2_5_0_, categories0_.CATE
GORYDESCRIPTION as CATEGORY3_5_0_, categories0_.ORDER_NUM as ORDER4_5_0_, categories0_.FK_PARENT_CAT
EGORYID as FK5_5_0_ from CATEGORIES categories0_ where categories0_.FK_SURVEYID=?
44359 [http-5555-Processor24] WARN  org.hibernate.util.JDBCExceptionReporter  SQL Error: 1054, SQLSt
ate: 42S22
44359 [http-5555-Processor24] ERROR org.hibernate.util.JDBCExceptionReporter  Unknown column 'catego
ries0_.FK_SURVEYID' in 'field list'
44468 [http-5555-Processor24] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/
surveystartool].[jsp]  Servlet.service() for servlet jsp threw exception
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [Survey.categories#1]
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1923)
        at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
        at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollect


Here the mapping file:

Code:
<hibernate-mapping>
  <class name="Category" table="CATEGORIES">
    <id name="categoryID" type="java.lang.Integer" column="CATEGORYID">
      <generator class="increment" />
    </id>
    <property name="categoryName" type="java.lang.String" column="CATEGORYNAME" />
    <property name="categoryDescription" type="java.lang.String" column="CATEGORYDESCRIPTION" />
    <property name="orderNum" type="java.lang.String" column="ORDER_NUM" />
    <many-to-one name="parentCategory"
                class="Category"
               column="FK_PARENT_CATEGORYID"
               insert="false" update="false"/>
    <set name="questions">
      <key column="FK_CATEGORYID" not-null="true"/>
      <one-to-many class="Question"/>
    </set>
  </class>
</hibernate-mapping>


The mapping of the parent table:

Code:
<hibernate-mapping>
  <class name="Survey" table="SURVEYS">
    <id name="surveyID" type="java.lang.Integer" column="SURVEYID">
      <generator class="increment" />
    </id>
    <property name="surveyName" type="java.lang.String" column="SURVEYNAME" />
    <set name="categories" table="CATEGORIES">
      <key column="FK_SURVEYID"/>
      <one-to-many class="Category"/>
    </set>
  </class>
</hibernate-mapping>


The sql dump:

Code:
CREATE TABLE  `surveystar_db`.`categories` (
  `CATEGORYID` int(10) unsigned NOT NULL auto_increment,
  `CATEGORYNAME` varchar(100) NOT NULL,
  `CATEGORYDESCRIPTION` varchar(300) NOT NULL,
  `ORDER_NUM` varchar(10) NOT NULL,
  PRIMARY KEY  (`CATEGORYID`),
  CONSTRAINT `FK_PARENT_CATEGORYID` FOREIGN KEY (`CATEGORYID`) REFERENCES `categories` (`CATEGORYID`),
  CONSTRAINT `FK_SURVEYID` FOREIGN KEY (`CATEGORYID`) REFERENCES `surveys` (`SURVEYID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Why is this no working?

Thanks for any help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.