Java Tutorial/Hibernate/Introduction — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 05:02, 1 июня 2010
Hibernate and HSQL
File: Main.java
import org.hibernate.Session;
public class Main {
public static void main(String[] args) throws Exception {
HibernateUtil hibernateUtil = new HibernateUtil();
hibernateUtil.executeSQLCommand("create table survey (id int,name varchar);");
Session session = hibernateUtil.getSession();
Survey survey = new Survey();
survey.setName("Survey");
System.out.println(survey.getId());
session.save(survey);
session.flush();
System.out.println(survey.getId());
Survey surveyInSession = (Survey) session.get(Survey.class, survey.getId());
System.out.println(surveyInSession.getName());
session.close();
hibernateUtil.checkData("select * from survey");
}
}
Setup Hibernate Environment
File: Main.java
import org.hibernate.Session;
public class Main {
public static void main(String[] args) throws Exception {
HibernateUtil hibernateUtil = new HibernateUtil();
hibernateUtil.executeSQLCommand("create table survey (id int,name varchar);");
Session session = hibernateUtil.getSession();
Survey survey = new Survey();
survey.setName("Survey");
System.out.println(survey.getId());
session.save(survey);
session.flush();
System.out.println(survey.getId());
Survey surveyInSession = (Survey) session.get(Survey.class, survey.getId());
System.out.println(surveyInSession.getName());
session.close();
hibernateUtil.checkData("select * from survey");
}
}