Ho creato una classe Honey con i seguenti campi
public class Honey {
private String name;
private String taste;
public Honey() {
}
.......cn varie funzioni per settare il name e taste..
poi ho creato il file hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql .jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:1703/mysql/firsthibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="Honey.hbm.xml"/>
</session-factory>
</hibernate-configuration>
poi ho creato il main così:
package roseindia.tutorial.hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* @author Deepak Kumar
*
* http://www.roseindia.net
* Hibernate example to inset data into Contact table
*/
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Transaction t=session.beginTransaction();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Honey forestHoney = new Honey();
forestHoney.setId(1);
forestHoney.setName("forest");
forestHoney.setTaste("very");
session.save(forestHoney);
t.commit();
System.out.println("fatto");
/*
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);*/
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
}
il problema è che nn fa un cavolo!!nella console si blocca a
16:14:30,529 INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
e nn da errori o eccezion...?!