Here's my code. VERY simple. "Hello World" simple.
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="connection.url">jdbc:derby://localhost:1527/HibernateDb;create=true</property>
<property name="connection.username">blank</property>
<property name="connection.password">blank</property>
<property name="hibernate.default_schema">TESTSCHEMA</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">2</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
<!-- Enable Hibernate's current session context -->
<!-- <property name="current_session_context_class">org.hibernate.context.ManagerSessionContext</property> -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">create</property> -->
<!-- Table mapping resources -->
<!-- <mapping resource="" /> -->
</session-factory>
</hibernate-configuration>
package com.rain.hibernateexpamples;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="Contacts")
public class Contact {
@Id
@GeneratedValue
private long contactId;
@Column(name="firstname", nullable=false)
private String firstName;
@Column(name="middleinitial")
private char middleInitial;
@Column(name="lastname", nullable=false)
private String lastName;
@Column(name="phonenumber")
private String phoneNumber;
@Column(name="emailaddress")
private String emailAddress;
public long getContactId() {
return contactId;
}
public void setContactId(long contactId) {
this.contactId = contactId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public char getMiddleInitial() {
return middleInitial;
}
public void setMiddleInitial(char middleInitial) {
this.middleInitial = middleInitial;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
}
package com.rain.hibernateexpamples;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestContact {
/**
* @param args
*/
public static void main(String[] args) {
AnnotationConfiguration annotationConfig = new AnnotationConfiguration();
annotationConfig.addAnnotatedClass(Contact.class);
annotationConfig.configure("hibernate.cfg.xml");
// generate table from class
// CAUTION:
// Run this line once to generate table.
// If ran again, table data and/or structure will be lost.
new SchemaExport(annotationConfig).create(true, true);
// test object; YES I'M ROUTING FOR THE LAKERS
// transient for now
Contact contact = new Contact();
contact.setFirstName("Kobe");
contact.setMiddleInitial('J');
contact.setLastName("Bryant");
contact.setPhoneNumber("555-555-5555");
contact.setEmailAddress("
[email protected]");
/*
* .jar list
* antlr-2.7.6.jar
* commons-collections-3.1.jar
* dom4j-1.6.1.jar
* hibernate3.jar
* javassist-3.9.0.GA.jar
* jta-1.1.jar
* log4j-1.2.8.jar
* derbyclient.jar
* slf4j-api-1.5.8.jar
* slf4j-log4j12-1.5.8.jar
* jpa.jar
*/
}
}