-->
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: Error of getting object from database in Hibernate
PostPosted: Fri May 30, 2014 8:56 pm 
Newbie

Joined: Fri May 30, 2014 8:46 pm
Posts: 2
I have a problem with getting object from MySQL for java object. Here is the problem:
package com.simpleprogrammer;

import org.hibernate.Session;

public class Program {

public static void main(String[] args) {

Session session = HibernateUtility.getSessionFactory().openSession();

session.beginTransaction();

User user = new User();
user.setName("Tony");
user.setGoal(250);
session.save(user);
session.getTransaction().commit();

session.beginTransaction();
User us = (User)session.get(User.class, 1);

System.out.println(us.getName());
System.out.println(us.getGoal());

session.getTransaction().commit();

session.close();
HibernateUtility.getSessionFactory().close();

}

}

At line User us = (User)session.get(User.class, 1) there will be a red line under "get". When I moved my pointer
to that "get" it said: -----> The method get(Class, Serializable) in the type Session is not applicable for the arguments (Class<T>, int)

I'm beginner. Please show me how to fix this problem. I'm using Hibernate 4.3.4 and Eclipse Kepler (both Hibernate and Eclipse are current versions)
Thank you very much!

PS: I have tried "load" instead of get. They still show the same message.


Top
 Profile  
 
 Post subject: Re: Error of getting object from database in Hibernate
PostPosted: Mon Jun 02, 2014 6:09 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
could you post the User class, please?


Top
 Profile  
 
 Post subject: Re: Error of getting object from database in Hibernate
PostPosted: Tue Jun 03, 2014 11:45 am 
Newbie

Joined: Fri May 30, 2014 8:46 pm
Posts: 2
I have figured it out just using wrapper class Integer(1) for id and it works. Thank alot


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.