-->
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.  [ 3 posts ] 
Author Message
 Post subject: Selectting child OK.. but cant load parent. What's up?
PostPosted: Sun Oct 23, 2005 10:13 am 
Newbie

Joined: Sun Oct 23, 2005 9:45 am
Posts: 3
Location: Tinton Falls, NJ
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.x
Mapping documents:
There are two objects that I'm concerned with here for this topic. The person
object is the "parent" object to lots of objects and is used everywhere in my
schema. The account object is the object that is used to validate logins and
here is where the rub is.

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Sat Oct 15 11:14:17 EDT 2005 -->
<hibernate-mapping package="com.schooner.hbm">

<class name="Person" table="person">
<id name="personId" column="person_id" type="java.lang.Integer">
<generator class="native"/>
</id>

<property name="givenName" column="given_name" type="java.lang.String" not-null="true" />
<property name="surname" column="surname" type="java.lang.String" not-null="true" />
<property name="emailAddr" column="email_addr" type="java.lang.String" not-null="true" />
<property name="hasAccount" column="has_account" type="java.lang.Byte" not-null="true" />
<property name="phoneNumber" column="phone_number" type="java.lang.String" />

<set name="accountSet" inverse="true">
<key column="person_id"/>
<one-to-many class="Account"/>
</set>

<set name="dogSet" inverse="true">
<key column="person_id"/>
<one-to-many class="Dog"/>
</set>

<set name="judgeSet" inverse="true">
<key column="person_id"/>
<one-to-many class="Judge"/>
</set>

<set name="trialEntriesSet" inverse="true">
<key column="person_id"/>
<one-to-many class="TrialEntries"/>
</set>
</class>

</hibernate-mapping>


<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Sat Oct 15 11:08:23 EDT 2005 -->
<hibernate-mapping package="com.schooner.hbm">

<class name="Account" table="account">
<id name="accountId" column="account_id" type="java.lang.Integer">
<generator class="native"/>
</id>

<property name="password" column="password" type="java.lang.String" not-null="true" />
<property name="userid" column="userid" type="java.lang.String" not-null="true" />

<many-to-one name="person" column="person_id" class="Person" not-null="true" />

<set name="roleMapSet" inverse="true">
<key column="account_id"/>
<one-to-many class="RoleMap"/>
</set>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

In the "service" module I use the following code to select the account object
from the database.

public Account GetAccountByID(String userid){
Account acct = null;
List myList = null;
Session session=null;

System.out.println("Entered: AccountService::GetAccountByID ID: " + userid);
try {
session = SessionFactory.currentSession();
Query q = session.createQuery("from Account as account"

+ " where account.userid = :id"


);

q.setParameter("id",userid);
acct = (Account) q.uniqueResult();
System.out.println("\tAccountService::GetAccountByID Returning: " +acct.getAccountId());
return acct;

} catch (ObjectNotFoundException onfe){
return null;
} catch (HibernateException e) {
System.err.println("Hibernate Exception caught:" + e.getMessage());
throw new RuntimeException(e);
}



}

and that works very well and is not where the problem lies.

In a servlet piece of code I do innocnelty enough the following:
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
ActionForward fwd = null;

String userid=loginForm.getUserid();
String passwd=loginForm.getPassword();
if (userid == null ){
fwd = mapping.findForward("failure");
return fwd;
}
if ( passwd == null ){
fwd = mapping.findForward("failure");
return fwd;
}
/** OK those weren't blank, let's press on. **/
Account acct = AccountService.GetInstnace().GetAccountByID(userid);
if ( acct == null ){ /** Non existant account **/
fwd = mapping.findForward("failure");
return fwd;
}
if ( (acct.getUserid().equals(userid)) && (acct.getPassword().equals(passwd))){
HttpSession session = request.getSession();
session.setAttribute("account",acct);
// This is where the blowup occurs....
System.out.println("Got back " + acct.getPerson().getEmailAddr());

fwd = mapping.findForward("success");
}
return fwd;


}

Full stack trace of any exception that occurs:
Entered: AccountService::GetAccountByID ID: peter
09:59:35,202 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/local/jakarta-tomcat-5.5.4/webapps/ROOT/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Hibernate: select account0_.account_id as account1_, account0_.password as password1_, account0_.userid as userid1_, account0_.person_id as person4_1_ from account account0_ where account0_.userid=?
AccountService::GetAccountByID Returning: 1
Hibernate: select person0_.person_id as person1_0_, person0_.given_name as given2_0_0_, person0_.surname as surname0_0_, person0_.email_addr as email4_0_0_, person0_.has_account as has5_0_0_, person0_.phone_number as phone6_0_0_ from person person0_ where person0_.person_id=?
09:59:38,976 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 22003
09:59:38,982 ERROR JDBCExceptionReporter:72 - Bad value for type byte : t
09:59:38,993 WARN RequestProcessor:538 - Unhandled Exception thrown: class org.hibernate.exception.GenericJDBCException
NotifyUtil::java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:836)
at org.netbeans.modules.web.monitor.server.NotifyUtil$RecordSender.run(NotifyUtil.java:237)

09:59:39,012 ERROR StandardWrapper[:action]:269 - Servlet.service() for servlet action threw exception
org.hibernate.exception.GenericJDBCException: could not load an entity: [com.schooner.hbm.Person#1]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1359)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at com.schooner.hbm.Person$$EnhancerByCGLIB$$af5e0b4.getEmailAddr(<generated>)
at org.agilitystewards.struts.action.LoginAction.execute(LoginAction.java:68)
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.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.postgresql.util.PSQLException: Bad value for type byte : t
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getByte(AbstractJdbc2ResultSet.java:1937)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getByte(AbstractJdbc2ResultSet.java:2201)
at org.hibernate.type.ByteType.get(ByteType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
at org.hibernate.loader.Loader.getRow(Loader.java:855)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
... 36 more

Name and version of the database you are using:
Postgresql 8.x
The generated SQL (show_sql=true):
Hibernate: select account0_.account_id as account1_, account0_.password as password1_, account0_.userid as userid1_, account0_.person_id as person4_1_ from account account0_ where account0_.userid=?
AccountService::GetAccountByID Returning: 1
Hibernate: select person0_.person_id as person1_0_, person0_.given_name as given2_0_0_, person0_.surname as surname0_0_, person0_.email_addr as email4_0_0_, person0_.has_account as has5_0_0_, person0_.phone_number as phone6_0_0_ from person person0_ where person0_.person_id=?
09:59:38,976 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 22003
09:59:38,982 ERROR JDBCExceptionReporter:72 - Bad value for type byte : t

The more I RTFM the more I think this should "jsut work" but it doesn't. Where am I
going wrong here?

_________________
Peter L. Berghold Peter at Berghold do Net
Old fashioned Unix Professional...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 5:57 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
take a look at ConnectException: Connection refused . check the usual suspects like database acl, firewalls, db server logs, etc.

how are you managing session.close() ?


Top
 Profile  
 
 Post subject: Nevermind... found the problem....
PostPosted: Sun Oct 23, 2005 10:17 pm 
Newbie

Joined: Sun Oct 23, 2005 9:45 am
Posts: 3
Location: Tinton Falls, NJ
Turns out there is a bug in the way myEclipse generates the hibernate configuration files for Postgres when it encounters booleans. Once I hand adjusted the defintion for the person table such that the type for the boolean was of type="boolean" the whole shebang started to work..


Sounds like I have to file a bug report with the myEclipse folks...

_________________
Peter L. Berghold Peter at Berghold do Net
Old fashioned Unix Professional...


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