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.