-->
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: DAO method depreciated warning
PostPosted: Wed Jul 19, 2006 12:18 am 
Beginner
Beginner

Joined: Wed May 10, 2006 9:43 pm
Posts: 30
Location: Australia
Hi everyone,

I am trying to get a simple DAO working to retrieve an object for a given id.

I found the below example and have been able to get it to work for my test app. The problem is the method "find" from the type session is deprecated. I haven't been able to find a solution.

Code:

public Geometry findById(Integer id) {
       Object object = null;
      Session session = null;
      try {
                   session = sessionFactory.openSession();
         List objects =
            session.find(
                "select g from " + Geometry.class.getName() + " as g where g.id = ?",
               new Object[] { id },
               new Type[] { Hibernate.INTEGER });
         
         if (objects != null && !objects.isEmpty()) {
            object = (Object) objects.get(0);
         }
      } catch (Exception e) {
         System.out.println("Error occurred while reading by ID: " + e);
      } finally {
         if (session != null) {
            try {
               session.close();
            } catch (Exception e) {
               System.out.println("Error occurred while closing session: " + e);
            }
         }
      }
      return (Geometry)object;
   }


To get this example to work I inserted the following imports
import org.hibernate.classic.Session;
import org.hibernate.type.Type;

If you can help please post your suggestions, I look forward to hearing from you.

Thanks, Alyssa.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 1:07 am 
Regular
Regular

Joined: Sat Nov 06, 2004 5:20 pm
Posts: 54
Location: Collierville, TN
Take a look at createQuery().

http://www.hibernate.org/hib_docs/v3/api/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 2:14 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
I think the hibernate.classic is probably an older version. From the javadoc it states:

Quote:
p
ublic interface Session
extends Session
An extension of the Session API, including all deprecated methods from Hibernate2. This interface is provided to allow easier migration of existing applications. New code should use org.hibernate.Session.


Based on the reference document, the use of "Query" object is recommended. You can do something like this instead:


Code:
Query tQuery = tSession.createQuery("select g from Geometry as g where g.id = ?");
tQuery.setInteger(1,1);
java.util.List tList = tQuery.list();



and "import org.hibernate.Session" instead of the "classic.Session".


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.