Tuesday, May 31, 2011

Java hibernate with mssql, posible mysql, oracle and anymore


Дээрхи зургийг татаж аваад үзээрэй.
Тэгээд дурайж хийхдээ:
1. add new NewHibernateUtil.java from hibernate category
2. add new Hibernate.cfg.xml from hibernate category

<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.url">jdbc:sqlserver://homework:1433;databaseName=MotelDb</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password"></property>

3. add new hibernate.reveng.xml from hibernate category

generate entity class with *.hbm.xml files

4. Session sess = NewHibernateUtil.getSessionFactory().openSession();
        Transaction tran = sess.beginTransaction();
       
        Role role = new Role();
        role.setName("clienta");
        role.setDescription(null);
        role.setIsActive(true);
        role.setCreated(new Date());
        role.setModified(new Date());
        role.setUserName("root");
       
        sess.saveOrUpdate(role);
       
        tran.commit();
        sess.close();

аан энэ бүхнээс эхэнд hibernate library add хийхээ мартваа тэгэхгүй бол import aldaa zaana

No comments: