-->
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.  [ 4 posts ] 
Author Message
 Post subject: one DB, multiple apps, & hibernate?
PostPosted: Mon Apr 19, 2004 6:01 pm 
Newbie

Joined: Thu Apr 15, 2004 7:18 pm
Posts: 2
Hi All,

We have a Hibernate/Java/JSP app and are replacing parts of the JSP frontend (& some of the hibernate middle layer) with PHP.

The PHP code is creating new objects & inserting the necessary related table rows. When we try to access (select) the PHP-created objects through the JSP/hibernate pages, we get the error below.

I haven't found anything (yet) in the PHP code/process which does not respect our hibernate mapping rules; I have some more digging to do, but was wondering if there is some general wisdom about hibernate sharing a DB with other apps? Any obvious gotchas, or things to look out for?

(fyi, the error occurs when trying to create an iterator on a hibernate Query object; I've tried creating an object in PHP [failed hiber retrieval] & creating the same object in JSP [successful retrieval], & then comparing verbose tomcat & mysql logs, but there were no useful differences).

Thanks,

Andy

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: String index out of range: 0
at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(Unknown Source)
at org.apache.catalina.core.ApplicationDispatcher.doForward(Unknown Source)
at org.apache.catalina.core.ApplicationDispatcher.forward(Unknown Source)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:309)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:387)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:673)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:615)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:786)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:534)


root cause

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:444)
at net.sf.hibernate.type.CharacterType.get(CharacterType.java:19)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:59)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:51)
at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:419)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:373)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:342)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:281)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:573)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:392)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1901)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1769)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1728)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:62)
at net.sf.hibernate.type.EntityType.nullSafeGet(EntityType.java:100)
at net.sf.hibernate.impl.IteratorImpl.postNext(IteratorImpl.java:57)
at net.sf.hibernate.impl.IteratorImpl.(IteratorImpl.java:43)
at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:790)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1422)
at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:64)
at org.groundspring.emailnow.webapp.action.member.MemberListMemberSearcher.getMembers(MemberListMemberSearcher.java:110)
at org.groundspring.emailnow.webapp.action.member.EditMembersAction.execute(EditMembersAction.java:260)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(Unknown Source)
at org.apache.catalina.core.ApplicationDispatcher.doForward(Unknown Source)
at org.apache.catalina.core.ApplicationDispatcher.forward(Unknown Source)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:309)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:387)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:673)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:615)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:786)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:534)



--------------------------------------------------------------------------------

Apache Tomcat/4.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 10:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well here's the snippet of code where this occurs:

Code:
public Object get(ResultSet rs, String name) throws SQLException {
    String str = rs.getString(name);
    if (str==null) {
        return null;
    }
    else {
        return new Character( str.charAt(0) );
    }
}


The only way that error is going to happen is if the value in the db is an empty string. Interesting that your two environments would handle it differently...


Top
 Profile  
 
 Post subject: Hibernate "char" field is not-null?
PostPosted: Tue Apr 20, 2004 1:58 pm 
Newbie

Joined: Thu Apr 15, 2004 7:18 pm
Posts: 2
Thanks for posting the code snippet -- i ran Hibernate from source & this is where it failed. The specific DB field that caused the failure is 'gender', set up in the DB as char(1), allow nulls & default to NULL. In the corresponding hbm.xml,

<property name="gender" column="gender" type="char"/>

So I'm still not sure why Hibernate is failing here -- is a "char" field supposed to be not-null? If so, guess I could fix it by changing it to varchar(1) in the DB ...

FYI running Hibernate 2.0.3.

Andy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 7:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
A primitive type property has to be mapped to a database column which does not contain nulls. Use a custom UserType otherwise which does mapping from null to some default value.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.