hibernate连接不到oracle 11g oracle SQL developer同一用户可以连接
packagemany2one;importorg.hibernate.Session;importorg.hibernate.SessionFactory;import...
package many2one;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class TestMany2one {
static SessionFactory sf;
public static void main(String[] args) {
Configuration cfg=new Configuration().configure();
sf=cfg.buildSessionFactory();
create();
read();
update();
delete();
sf.close();
}
public static void create(){
Session session= sf.openSession();
Dept d=new Dept();
d.setName("IT");
d.setTelephone("1111111");
session.save(d);
Employee e=new Employee();
e.setName("w");
e.setAge(18);
e.setGender("男");
e.setDepart(d);
session.save(e);
session.beginTransaction().commit();
session.close();
sf.close();
}
public static void read(){
Session session= sf.openSession();
Employee e=(Employee) session.get(Employee.class, 1);
System.out.println(e);
System.out.println(e.getDepart());
}
public static void update(){
Session session =sf.openSession();
Employee e=(Employee) session.get(Employee.class, 1);
e.setName("123123");
session.update(e);
}
public static void delete(){
Session session =sf.openSession();
Employee e=new Employee();
}
} 展开
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class TestMany2one {
static SessionFactory sf;
public static void main(String[] args) {
Configuration cfg=new Configuration().configure();
sf=cfg.buildSessionFactory();
create();
read();
update();
delete();
sf.close();
}
public static void create(){
Session session= sf.openSession();
Dept d=new Dept();
d.setName("IT");
d.setTelephone("1111111");
session.save(d);
Employee e=new Employee();
e.setName("w");
e.setAge(18);
e.setGender("男");
e.setDepart(d);
session.save(e);
session.beginTransaction().commit();
session.close();
sf.close();
}
public static void read(){
Session session= sf.openSession();
Employee e=(Employee) session.get(Employee.class, 1);
System.out.println(e);
System.out.println(e.getDepart());
}
public static void update(){
Session session =sf.openSession();
Employee e=(Employee) session.get(Employee.class, 1);
e.setName("123123");
session.update(e);
}
public static void delete(){
Session session =sf.openSession();
Employee e=new Employee();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询