Well, make sure your schema is created, and then, to create tables use a SchemaExport:
Code:
public static void main(String args[]) {
AnnotationConfiguration config =
new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
config.configure();
new SchemaExport(config).create(true, true);
}
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=01howtogetstartedwithhibernateThat will create the tables you need. Then, just code some CRUD methods!
Code:
config.addAnnotatedClass(User.class);
config.configure();
// new SchemaExport(config).create(true, true);
SessionFactory factory =
config.buildSessionFactory();
Session session = factory.getCurrentSession();
session.beginTransaction();
System.out.println("creating user");
User u = new User();
u.setPassword("abc123");
session.saveOrUpdate(u);
System.out.println("user saved");
session.getTransaction().commit();
System.out.println("transaction successful!!!");
But of course, make sure your hibernate.cfg.xml file has all the proper dialects for your database, connection URLs, usernames and passwords:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/
hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">
jdbc:mysql://localhost/examscam
</property>
<property name="connection.username">
root
</property>
<property name="connection.password">
password
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="current_session_context_class">
thread
</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">
true
</property>
<!-- mapping files -->
</session-factory>
</hibernate-configuration>
Check out this tutorial on setting up Hibernate:
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=01howtogetstartedwithhibernate