Hey Guys,
can somebody explain me why i get this ugly "can not initialize a collection"error?
First i wanna post my code and config-file for a little overview:
This are my Methods am using(this one and nothing else):
Code:
public UserVO login(String username, String password) {
Session sess = getSessionFactory().openSession();
Query q = sess.createQuery("from UserVO where username='" + username
+ "'");
if (q.list().size() == 0)
return null;
UserVO user = (UserVO)q.list().get(0);
if(user.getPassword().equals(password)){
return user;
}else{
return null;
}
}
public boolean register(UserVO newUser) {
try {
Session sess = getSessionFactory().openSession();
Query q = sess.createQuery("from UserVO where username='"
+ newUser.getUsername() + "'");
if (q.list().size() > 0) {
return false;
} else {
Transaction trans = sess.beginTransaction();
sess.save(newUser);
trans.commit();
}
sess.close();
return true;
} catch (HibernateException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
return false;
}
}
Now my Mapping File:
Code:
<hibernate-mapping package="vo">
<class name="UserVO">
<id name="id">
<generator class="native"/>
</id>
<property name="username"/>
<property name="password"/>
<property name="email"/>
<list name="favCategories">
<key column="userID"/>
<list-index column="index"/>
<many-to-many column="categoryID" class="vo.CategoryVO"/>
</list>
<list name="books" cascade="all">
<key column="userID"/>
<list-index column="index"/>
<many-to-many column="bookID" class="vo.BookVO"/>
</list>
</class>
</hibernate-mapping>
So when i call the register-method everything works fine. The User is created in the database. But when i want to login the console is showing the following:
Code:
[size=9]Exception occurred during serialization: org.hibernate.exception.SQL
mmarException: could not initialize a collection: [vo.UserVO.books#1
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConvert
ava:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCException
er.java:66)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2022)
at org.hibernate.loader.collection.CollectionLoader.initialize(Colle
nLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.in
lize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.
itializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.j
1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(
ractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(Abstra
rsistentCollection.java:108)
at org.hibernate.collection.PersistentList.toArray(PersistentList.ja
46)
at java.util.ArrayList.<init>(ArrayList.java:131)
at flex.messaging.io.ArrayCollection.<init>(ArrayCollection.java:44)
at flex.messaging.io.amf.Amf3Output.writeArrayCollection(Amf3Output.
:462)
at flex.messaging.io.amf.Amf3Output.writeObject(Amf3Output.java:182)
at flex.messaging.io.amf.Java15Amf3Output.writeObject(Java15Amf3Outp
ava:58)
at flex.messaging.io.amf.Amf3Output.writeObjectProperty(Amf3Output.j
250)
at flex.messaging.io.amf.Amf3Output.writePropertyProxy(Amf3Output.ja
73)
at flex.messaging.io.amf.Amf3Output.writeCustomObject(Amf3Output.jav
5)
at flex.messaging.io.amf.Amf3Output.writeObject(Amf3Output.java:200)
at flex.messaging.io.amf.Java15Amf3Output.writeObject(Java15Amf3Outp
ava:58)
at flex.messaging.messages.AbstractMessage.writeExternal(AbstractMes
.java:353)
at flex.messaging.messages.AsyncMessage.writeExternal(AsyncMessage.j
140)
at flex.messaging.messages.AcknowledgeMessage.writeExternal(Acknowle
essage.java:93)
at flex.messaging.messages.AcknowledgeMessageExt.writeExternal(Ackno
geMessageExt.java:55)
at flex.messaging.io.amf.Amf3Output.writePropertyProxy(Amf3Output.ja
63)
at flex.messaging.io.amf.Amf3Output.writeCustomObject(Amf3Output.jav
5)
at flex.messaging.io.amf.Amf3Output.writeObject(Amf3Output.java:112)
at flex.messaging.io.amf.Java15Amf3Output.writeObject(Java15Amf3Outp
ava:58)
at flex.messaging.io.amf.Amf0Output.writeObject(Amf0Output.java:198)
at flex.messaging.io.amf.Java15Amf0Output.writeObject(Java15Amf0Outp
ava:69)
at flex.messaging.io.amf.AmfMessageSerializer.writeObject(AmfMessage
alizer.java:196)
at flex.messaging.io.amf.AmfMessageSerializer.writeBody(AmfMessageSe
izer.java:186)
at flex.messaging.io.amf.AmfMessageSerializer.writeMessage(AmfMessag
ializer.java:142)
at flex.messaging.endpoints.amf.SerializationFilter.invoke(Serializa
Filter.java:179)
at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoin
va:278)
at flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.
:322)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicat
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrap
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardCont
alve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostVal
ava:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportVal
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngin
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter
a:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.
:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.p
ss(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.jav
7)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'deskc
favcategories' doesn't exist
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatemen
va:1332)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.j
1467)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.j
208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollection
ader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
... 46 more
21.02.2009 22:25:40 org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/deskcook]
log4j:ERROR LogMananger.repositorySelector was null likely due to error in c
reloading, using NOPLoggerRepository.
21.02.2009 22:25:40 org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive deskcook.war
21.02.2009 22:25:42 org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already
ould not load java.net.BindException. The eventual following stack trace is
sed by an error thrown for debugging purposes as well as to attempt to termi
the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClas
der.java:1244)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClas
der.java:1204)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at com.mysql.jdbc.CommunicationsException.<init>(CommunicationsExcep
.java:161)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2759)
at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1410)
at com.mysql.jdbc.Connection.realClose(Connection.java:4947)
at com.mysql.jdbc.Connection.cleanup(Connection.java:2063)
at com.mysql.jdbc.Connection.finalize(Connection.java:3403)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)[/size]
I think my mapping is correct?!(hopefully) The only intressting think is,when i create a user (calling save()) hibernate doesn't create the table to map the context between User and Book. Maybe that is so,because at registration time a user hasn't got any Book? I really don't know!
I hope there is somebody who can bring a little bit light in this really dark room!
Greetz
Flavy
AND THANKS!