-->
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: SQLGrammarException: could not initialize a collection
PostPosted: Tue Jun 11, 2013 9:01 am 
Newbie

Joined: Tue Jun 11, 2013 8:38 am
Posts: 1
Hey there,

I´m pretty new to hibernate mappings and after crwaling this forum without any solution to adapt I end up writing this post.

Anyway here is the exception:
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [main.domain.ProfileDescription.courses#6]
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [main.domain.ProfileDescription.courses#6]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1992)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at main.domain.collaborativeRecommender.DataBaseConnector.retrieveAllCases(DataBaseConnector.java:193)
at jcolibri.extensions.recommendation.collaborative.MatrixCaseBase.init(MatrixCaseBase.java:130)
at main.domain.collaborativeRecommender.LMSRecommender.preCycle(LMSRecommender.java:77)
at main.domain.collaborativeRecommender.LMSRecommender.main(LMSRecommender.java:167)
Caused by: java.sql.SQLException: Table not found in statement [select courses0_.usr_ID as usr3_1_, courses0_.course_ID as course1_1_, courses0_.course_ID as course1_0_0_, courses0_.course_name as course2_0_0_, courses0_.usr_ID as usr3_0_0_ from LMS_COURSE courses0_ where courses0_.usr_ID=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
... 19 more

And here the java code:
Code:
public class ProfileDescription implements CaseComponent {

   Integer caseID;
   Integer id;
   Integer zipCode;
   Integer avgGrade;
   Integer avgDifficulty;
   Integer avgEvaluation;
   String coursesDone;
   Set<Course> courses = new HashSet<Course>();

public class Course implements CaseComponent {

   Integer id;
   String name;
   ProfileDescription profile;


The database schema:

Code:
create table LMS_REC (id INTEGER,usr_ID INTEGER not null,usr_name varchar(100),usr_zipcode INTEGER,usr_avg_grade INTEGER, usr_avg_difficulty INTEGER, usr_avg_eval INTEGER,course_ID INTEGER,usr_courses_done varchar(200),doc_ID INTEGER,doc_num INTEGER,doc_name varchar(100),doc_subject varchar(100),doc_difficulty INTEGER,id2 INTEGER,rat_ID INTEGER,rat_rating INTEGER,primary key (usr_ID));

create table LMS_COURSE (course_ID INTEGER not null,course_name varchar(100),usr_ID INTEGER,primary key (course_ID),index fk_course (usr_ID),constraint fk_courses foreign key (usr_ID) references LMS_REC (usr_ID));


And finally the mappings:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
   <class name="main.domain.CMS.Course" table="LMS_COURSE">
      <id name="id" column="course_ID">
         <generator class="native" />
      </id>
      <property name="name" column="course_name" />
      <many-to-one name="profile" class="main.domain.ProfileDescription"
         column="usr_ID" insert="false" update="false" not-null="true" />
   </class>
   <class name="main.domain.ProfileDescription" table="LMS_REC">
      <id name="id" column="usr_ID">
         <generator class="native" />
      </id>
      <property name="caseID" column="id" />
      <property name="zipCode" column="usr_zipcode" />
      <property name="avgGrade" column="usr_avg_grade" />
      <property name="avgDifficulty" column="usr_avg_difficulty" />
      <property name="avgEvaluation" column="usr_avg_eval" />
      <property name="coursesDone" column="usr_courses_done" />
      <set name="courses" table="LMS_COURSE" inverse="true" fetch="select">
         <key column="usr_ID" not-null="true" />
         <one-to-many class="main.domain.CMS.Course" />
      </set>
   </class>
</hibernate-mapping>


So that´s all. I´m searching a while already, learning more and more about hibernate.
But I hope somebody can point out where the exception comes from! :)

Thanks in advance.
Tell


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.