HHH-5441 - Create "Getting Started Guide" - separate tutorial project for bundling
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20278 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
1532e22327
commit
b4ac7275e5
|
@ -1,36 +0,0 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
|
||||
<session-factory>
|
||||
|
||||
<!-- Database connection settings -->
|
||||
<property name="connection.driver_class">org.h2.Driver</property>
|
||||
<property name="connection.url">jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</property>
|
||||
<property name="connection.username">sa</property>
|
||||
<property name="connection.password"></property>
|
||||
|
||||
<!-- JDBC connection pool (use the built-in) -->
|
||||
<property name="connection.pool_size">1</property>
|
||||
|
||||
<!-- SQL dialect -->
|
||||
<property name="dialect">org.hibernate.dialect.H2Dialect</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">update</property>
|
||||
|
||||
<!-- Names the annotated entity class -->
|
||||
<mapping class="org.hibernate.tutorial.annotations.Event"/>
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
|
@ -1,47 +0,0 @@
|
|||
package org.hibernate.tutorial.annotations;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
@Entity
|
||||
@Table( name = "EVENTS" )
|
||||
public class Event {
|
||||
private Long id;
|
||||
|
||||
private String title;
|
||||
private Date date;
|
||||
|
||||
public Event() {}
|
||||
|
||||
@Id
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "EVENT_DATE")
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.tutorial.annotations;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class EventManager {
|
||||
private final SessionFactory sessionFactory;
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventManager eventManager = new EventManager();
|
||||
|
||||
if ( args[0].equals( "store" ) ) {
|
||||
eventManager.createAndStoreEvent( "My Event", new Date() );
|
||||
}
|
||||
else if (args[0].equals("list")) {
|
||||
List events = eventManager.listEvents();
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
Event theEvent = (Event) events.get(i);
|
||||
System.out.println(
|
||||
"Event: " + theEvent.getTitle()
|
||||
+ " Time: " + theEvent.getDate()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
eventManager.release();
|
||||
}
|
||||
|
||||
public EventManager() {
|
||||
sessionFactory = new Configuration()
|
||||
.configure() // configures settings from hibernate.cfg.xml
|
||||
.buildSessionFactory();
|
||||
}
|
||||
|
||||
public void release() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
|
||||
private void createAndStoreEvent(String title, Date theDate) {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Event theEvent = new Event();
|
||||
theEvent.setTitle( title );
|
||||
theEvent.setDate( theDate );
|
||||
session.save( theEvent );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private List listEvents() {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
List result = session.createQuery("from Event").list();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.hibernate.tutorials</groupId>
|
||||
<artifactId>hibernate-tutorial-annotations</artifactId>
|
||||
<version>3.6.0-SNAPSHOT</version>
|
||||
<name>Hibernate Annotations Tutorial</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate gives you a choice of bytecode providers between cglib and javassist -->
|
||||
<dependency>
|
||||
<groupId>javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- The tutorial uses the H2 in-memory database -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,17 +0,0 @@
|
|||
[hibernateTutorial]$ mvn compile
|
||||
[INFO] Scanning for projects...
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Building First Hibernate Tutorial
|
||||
[INFO] task-segment: [compile]
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] [resources:resources]
|
||||
[INFO] Using default encoding to copy filtered resources.
|
||||
[INFO] [compiler:compile]
|
||||
[INFO] Compiling 2 source file to hibernateTutorial/target/classes
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESSFUL
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 2 seconds
|
||||
[INFO] Finished at: Tue Jun 09 12:25:25 CDT 2009
|
||||
[INFO] Final Memory: 5M/547M
|
||||
[INFO] ------------------------------------------------------------------------
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
|
||||
<session-factory>
|
||||
|
||||
<!-- Database connection settings -->
|
||||
<property name="connection.driver_class">org.h2.Driver</property>
|
||||
<property name="connection.url">jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE</property>
|
||||
<property name="connection.username">sa</property>
|
||||
<property name="connection.password"></property>
|
||||
|
||||
<!-- JDBC connection pool (use the built-in) -->
|
||||
<property name="connection.pool_size">1</property>
|
||||
|
||||
<!-- SQL dialect -->
|
||||
<property name="dialect">org.hibernate.dialect.H2Dialect</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">update</property>
|
||||
|
||||
<mapping resource="org/hibernate/tutorial/hbm/Event.hbm.xml"/>
|
||||
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
|
@ -1,11 +0,0 @@
|
|||
<hibernate-mapping package="org.hibernate.tutorial.hbm">
|
||||
|
||||
<class name="Event" table="EVENTS">
|
||||
<id name="id" column="EVENT_ID">
|
||||
<generator class="enhanced-sequence"/>
|
||||
</id>
|
||||
<property name="date" type="timestamp" column="EVENT_DATE"/>
|
||||
<property name="title"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -1,36 +0,0 @@
|
|||
package org.hibernate.tutorial.hbm;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Event {
|
||||
private Long id;
|
||||
|
||||
private String title;
|
||||
private Date date;
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package org.hibernate.tutorial.hbm;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class EventManager {
|
||||
private final SessionFactory sessionFactory;
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventManager eventManager = new EventManager();
|
||||
|
||||
if ( args[0].equals( "store" ) ) {
|
||||
eventManager.createAndStoreEvent( "My Event", new Date() );
|
||||
}
|
||||
else if (args[0].equals("list")) {
|
||||
List events = eventManager.listEvents();
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
Event theEvent = (Event) events.get(i);
|
||||
System.out.println(
|
||||
"Event: " + theEvent.getTitle()
|
||||
+ " Time: " + theEvent.getDate()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
eventManager.release();
|
||||
}
|
||||
|
||||
public EventManager() {
|
||||
sessionFactory = new Configuration()
|
||||
.configure() // configures settings from hibernate.cfg.xml
|
||||
.buildSessionFactory();
|
||||
}
|
||||
|
||||
public void release() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
|
||||
private void createAndStoreEvent(String title, Date theDate) {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
Event theEvent = new Event();
|
||||
theEvent.setTitle( title );
|
||||
theEvent.setDate( theDate );
|
||||
session.save( theEvent );
|
||||
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private List listEvents() {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
List result = session.createQuery("from Event").list();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.hibernate.tutorials</groupId>
|
||||
<artifactId>hibernate-tutorial-hbm</artifactId>
|
||||
<version>3.6.0-SNAPSHOT</version>
|
||||
<name>Hibernate hbm.xml Tutorial</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate gives you a choice of bytecode providers between cglib and javassist -->
|
||||
<dependency>
|
||||
<groupId>javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- The tutorial uses the H2 in-memory database -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue