/////////////////////////////////////////////////////////////////////////
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class SimpleSaveTest {
public static void main(String[] args) {
HibernateUtil.setup("create table EVENTS ( EVENT_ID int, EVENT_DATE date, title VARCHAR);");
// hibernate code start
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle("My Event");
theEvent.setDate(new Date());
session.save(theEvent);
tx.commit();
HibernateUtil.closeSession();
HibernateUtil.sessionFactory.close();
// hibernate code end
HibernateUtil.checkData("select * from events;");
}
}
/////////////////////////////////////////////////////////////////////////
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
type="date"/>
class="Location"/>
/////////////////////////////////////////////////////////////////////////
import java.util.Date;
public class Event {
private Long id;
private String title;
private Date date;
Event() {
}
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String toString() {
return "ID:" + id + "\nTitle:" + title + "\nDate:" + date;
}
}
HibernateSaveDateType.zip( 4,581 k)