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.
|