-->
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: CreateQuery / Session.get is not returning objects
PostPosted: Sat Nov 14, 2009 8:22 am 
Newbie

Joined: Sat Nov 14, 2009 8:07 am
Posts: 1
When I invoke getJbossPortal() method, it returns Number of Objects fetched as zero.

I tried with get method also like this :

Jbossportal jbs=(Jbossportal) session.get(Jbossportal.class, id.trim());

But it returns null. I am struggling with this for the past 2 days.

Any help is highly appreciated.

I have given my dao source and xml file contents below:

DAO Class:
public class JbossportalDAO {
public JbossportalDAO()
{
super();
}
public String getJbossportal()
{
try
{
HibernateUtil hutil =new HibernateUtil();
Session session= hutil.getSessionFactory().getCurrentSession();
try
{ String s = "";

session.beginTransaction();
Query q = session.createQuery("from Jbossportal" );
s = "Number of Objects: " + q.list().size();
session.getTransaction().commit();
return s;
}
catch(Exception e) {
return e.toString();
}
finally{
//session.close();
}
}
catch(Exception e) {
return e.toString();
}
}
}

Jbossportal.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 11, 2009 11:36:12 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="org.jboss.portlet.hello.Jbossportal" table="jbossportal" >
<id name="empid" type="string">
<column name="EMPID" length="20" />
<generator class="assigned" />
</id>
<property name="firstName" type="string">
<column name="FIRST_NAME" length="20" />
</property>
<property name="lastName" type="string">
<column name="LAST_NAME" length="10" />
</property>
<property name="duration" type="string">
<column name="DURATION" length="20" />
</property>
</class>
</hibernate-mapping>

hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:/data/hypersonic/localDB</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="hibernate.show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="Cache.use_second_level_cache">true</property>
<property name="Cache.use_query_cache">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="Cache.provider_class">org.hibernate.cache.EhCacheprovider</property>
<mapping resource="org/jboss/portlet/hello/Jbossportal.hbm.xml"/>
</session-factory>
</hibernate-configuration>


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.