-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hql question?
PostPosted: Wed Sep 07, 2005 9:06 pm 
Newbie

Joined: Wed Sep 07, 2005 12:02 am
Posts: 7
Query query = session.createQuery("from Jobs as j"); in Hibernate runs smoothly, but in Hibernate 3 doesnot run.
I use eclipse create two projects, one used hibernate2 the other used hibernate 3. Both projects codes are the same, except the jar files in lib.
I have no ideas about it , is there some gentlemen konwing the reason.
Thank a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 9:09 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Exception?
Mapping files?

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 9:31 pm 
Newbie

Joined: Wed Sep 07, 2005 12:02 am
Posts: 7
Yes something wrong in Jobs.hbm.xml.
<hibernate-mapping package="com.testHib">

<class name="com.testHib.Jobs" table="jobs">
<id name="jobId" column="job_id" type="short">

</id>
Thanks for sven.
But I find another problem.
The page 'showdata.jsp' which displays some columns of 'Table Jobs' displays normally.
But if I refresh this page twice, it will throws Exception. Tomcat says cannot obtain the connection.
Is someone knowing the reason?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 10:15 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Exception?
Mapping files?

This time, show the stack trace of the exception. Show the whole mapping file.

Your "mapping file" appears to follow the older 2.0 DTD. We'd know for sure had you posted the whole thing. This is because the column is specified as an attribute of id, rather than a child element.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:28 pm 
Newbie

Joined: Wed Sep 07, 2005 12:02 am
Posts: 7
Exception:
Hibernate ExceptionNot able to obtain connection

com.testHib.Jobs

<?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 Wed Sep 07 11:47:04 CST 2005 -->
<hibernate-mapping package="com.testHib">

<class name="Jobs" table="jobs">
<id name="jobId" column="job_id" type="short">

</id>

<property name="jobDesc" column="job_desc" type="string" not-null="true" />
<property name="minLvl" column="min_lvl" type="short" not-null="true" />
<property name="maxLvl" column="max_lvl" type="short" not-null="true" />

<!-- <set name="employeeSet" inverse="true">
<key column="job_id"/>
<one-to-many class="Employee"/>
</set>
-->
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:30 pm 
Newbie

Joined: Wed Sep 07, 2005 12:02 am
Posts: 7
hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">dbconn1</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://server2;DatabaseName=pubs
</property>
<property name="connection.username">user</property>
<property name="connection.password">user</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="show_sql">true</property>
<mapping resource="com/testHib/Authors.hbm.xml" />
<mapping resource="com/testHib/Jobs.hbm.xml" />


</session-factory>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 1:02 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
The most likely situation is that each time you refresh the page, you are opening a connection but not closing it, starving the connection pool. Make sure you are closing the Session and disregard anything I said earlier about the validity of the XML .


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 1:38 am 
Newbie

Joined: Wed Sep 07, 2005 12:02 am
Posts: 7
Thanks dennisbyrne very much.
You are right. I do close the session by the method (session.close();), but not close the sessionfactory.
Now it runs normally, thanks you again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 1:55 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
thesis100 wrote:
You are right. I do close the session by the method (session.close();), but not close the sessionfactory.


Uhm ... sessionFactory.close() is probably not a good idea.

thesis100 wrote:
Now it runs normally, thanks you again.


Well, log back in and rate the post as helpful then.


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