diff --git a/hibernate-immutable/README.md b/hibernate-immutable/README.md deleted file mode 100644 index f564d8fc3f..0000000000 --- a/hibernate-immutable/README.md +++ /dev/null @@ -1,2 +0,0 @@ -Article -- [Guide to @Immutable Annotation in Hibernate](http://inprogress.baeldung.com/?p=35824&preview=true) diff --git a/hibernate-immutable/pom.xml b/hibernate-immutable/pom.xml deleted file mode 100644 index f4ed2d3cf4..0000000000 --- a/hibernate-immutable/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - 4.0.0 - - com.baeldung - hibernate-immutable - 1.0-SNAPSHOT - - - - org.hibernate - hibernate-core - 4.3.10.Final - - - org.hsqldb - hsqldb - 2.2.9 - - - junit - junit - 4.11 - test - - - - \ No newline at end of file diff --git a/hibernate-immutable/src/main/java/com/baeldung/entities/Event.java b/hibernate-immutable/src/main/java/com/baeldung/entities/Event.java deleted file mode 100644 index a8690a8959..0000000000 --- a/hibernate-immutable/src/main/java/com/baeldung/entities/Event.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.entities; - -import org.hibernate.annotations.*; -import org.hibernate.annotations.CascadeType; - -import javax.persistence.*; -import javax.persistence.Entity; -import javax.persistence.Table; -import java.util.Set; - -@Entity -@Immutable -@Table(name = "events") -public class Event { - @Id - @Column(name = "event_id") - @GeneratedValue(generator = "increment") - @GenericGenerator(name = "increment", strategy = "increment") - private Long id; - - @Column(name = "title") - private String title; - - @ElementCollection - @Immutable - private Set guestList; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE}) - public Set getGuestList() { - return guestList; - } - - public void setGuestList(Set guestList) { - this.guestList = guestList; - } -} diff --git a/hibernate-immutable/src/main/java/com/baeldung/util/HibernateUtil.java b/hibernate-immutable/src/main/java/com/baeldung/util/HibernateUtil.java deleted file mode 100644 index f802342b86..0000000000 --- a/hibernate-immutable/src/main/java/com/baeldung/util/HibernateUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.util; - -import org.hibernate.SessionFactory; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.hibernate.service.ServiceRegistry; - -public class HibernateUtil { - private static final SessionFactory sessionFactory = buildSessionFactory(); - - private static SessionFactory buildSessionFactory() { - try { - // Create a session factory from hibernate.cfg.xml - Configuration configuration = new Configuration(); - configuration.configure("hibernate.cfg.xml"); - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() - .applySettings(configuration.getProperties()) - .build(); - return configuration.buildSessionFactory(serviceRegistry); - } catch (Throwable ex) { - System.out.println("Initial SessionFactory creation failed." + ex); - throw new ExceptionInInitializerError(ex); - } - } - - public static SessionFactory getSessionFactory() { - return sessionFactory; - } -} diff --git a/hibernate-immutable/src/main/resources/hibernate.cfg.xml b/hibernate-immutable/src/main/resources/hibernate.cfg.xml deleted file mode 100644 index 756191a9e2..0000000000 --- a/hibernate-immutable/src/main/resources/hibernate.cfg.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - org.hsqldb.jdbcDriver - jdbc:hsqldb:hsql://localhost/xdb - sa - - - - 1 - - - org.hibernate.dialect.HSQLDialect - - - thread - - - org.hibernate.cache.NoCacheProvider - - - true - - - update - - - - - - \ No newline at end of file diff --git a/hibernate-immutable/src/test/java/EventTest.java b/hibernate-immutable/src/test/java/EventTest.java deleted file mode 100644 index f05aaff5f5..0000000000 --- a/hibernate-immutable/src/test/java/EventTest.java +++ /dev/null @@ -1,78 +0,0 @@ -import com.baeldung.entities.Event; -import com.baeldung.util.HibernateUtil; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import javax.persistence.Table; - -public class EventTest { - - private Session session; - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Before - public void setup() { - session = HibernateUtil.getSessionFactory().getCurrentSession(); - session.beginTransaction(); - } - - @After - public void teardown() { - HibernateUtil.getSessionFactory().close(); - } - - @Test - public void addEvent() { - Event event = new Event(); - event.setTitle("Public Event"); - session.save(event); - session.getTransaction().commit(); - } - - @Test - public void updateEvent() { - Event event = (Event) session.createQuery( - "FROM Event WHERE title='My Event'").list().get(0); - event.setTitle("Public Event"); - session.saveOrUpdate(event); - session.getTransaction().commit(); - } - - @Test - public void deleteEvent() { - Event event = (Event) session.createQuery( - "FROM Event WHERE title='My Event'").list().get(0); - session.delete(event); - session.getTransaction().commit(); - } - - @Test - public void addGuest() { - Event event = (Event) session.createQuery( - "FROM Event WHERE title='Public Event'").list().get(0); - String newGuest = "Sara"; - event.getGuestList().add(newGuest); - - exception.expect(HibernateException.class); - session.save(event); - session.getTransaction().commit(); - } - - @Test - public void deleteCascade() { - Event event = (Event) session.createQuery( - "FROM Event WHERE title='Public Event'").list().get(0); - String guest = event.getGuestList().iterator().next(); - event.getGuestList().remove(guest); - - exception.expect(HibernateException.class); - session.saveOrUpdate(event); - session.getTransaction().commit(); - } -}