Import org.hibernate.HibernateException;
Import org.hibernate.Session;
Import Org.hibernate.SessionFactory;
Import Org.springframework.beans.factory.BeanFactory;
Import Org.springframework.beans.factory.xml.XmlBeanFactory;
Import Org.springframework.core.io.ClassPathResource;
Import Org.springframework.core.io.Resource;
public class Planmachinetest {
private static final sessionfactory sessionfactory;
static {
try {
Resource resource=new Classpathresource ("/applicationcontext.xml");
Beanfactory factory=new xmlbeanfactory (Resource);
Sessionfactory = (sessionfactory) factory.getbean ("Sessionfactory");
} catch (Hibernateexception ex) {
throw new RuntimeException ("Exception Building sessionfactory:"
+ Ex.getmessage (), ex);
} 
} 
public static void Main (string[] args) {
session Session = Sessionfactory.opensession ();
machine m = (machine) session.get (Machine.class, 1);
planmachine pm = new Planmachine ();
Pm.setmachine (m);
Save (PM);
}
public static void Save (Object o) {
Session session = Sessionfacto Ry.opensession ();
session.begintransaction ();
Session.save (o);
session.gettransaction (). commit ();
session.close ();
sessionfactory.close ();
}
}
SSH hosts hibernate to spring get session