Author: hardy.ferentschik
Date: 2008-06-19 12:34:50 -0400 (Thu, 19 Jun 2008)
New Revision: 14790
Added:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java
Log:
Some tests for @immutable - not quite sure so if one can test like this.
Added:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml
(rev 0)
+++
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml 2008-06-19
16:34:50 UTC (rev 14790)
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<!-- Generated Nov 9, 2006 6:27:53 PM by Hibernate Tools 3.2.0.beta7 -->
+<hibernate-mapping>
+ <class name="org.hibernate.test.annotations.immutable.CountryHbm"
mutable="false">
+ <id name="id" column="id"
type="java.lang.Integer">
+ <generator class="native"/>
+ </id>
+ <property name="name"/>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Property changes on:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.hbm.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java
(rev 0)
+++
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java 2008-06-19
16:34:50 UTC (rev 14790)
@@ -0,0 +1,39 @@
+//$Id$
+package org.hibernate.test.annotations.immutable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.Immutable;
+
+@Entity
+@Immutable
+@SuppressWarnings("serial")
+public class Country implements Serializable {
+ private Integer id;
+ private String name;
+
+ @Id
+ @GeneratedValue
+ public Integer getId() {
+ return id;
+ }
+
+ @Immutable
+ public String getName() {
+ return name;
+ }
+
+ public void setId(Integer integer) {
+ id = integer;
+ }
+
+ public void setName(String string) {
+ name = string;
+ }
+}
Property changes on:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/Country.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java
(rev 0)
+++
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java 2008-06-19
16:34:50 UTC (rev 14790)
@@ -0,0 +1,29 @@
+//$Id$
+package org.hibernate.test.annotations.immutable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+public class CountryHbm implements Serializable {
+ private Integer id;
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setId(Integer integer) {
+ id = integer;
+ }
+
+ public void setName(String string) {
+ name = string;
+ }
+}
Property changes on:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/CountryHbm.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java
===================================================================
---
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java
(rev 0)
+++
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java 2008-06-19
16:34:50 UTC (rev 14790)
@@ -0,0 +1,85 @@
+//$Id$
+package org.hibernate.test.annotations.immutable;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.annotations.TestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for <code>Immutable</code> annotation.
+ *
+ * @author Hardy Ferentschik
+ */
+@SuppressWarnings("unchecked")
+public class ImmutableTest extends TestCase {
+
+ private Logger log = LoggerFactory.getLogger(ImmutableTest.class);
+
+ public ImmutableTest(String x) {
+ super(x);
+ }
+
+ public void testImmutableEntity() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Country country = new Country();
+ country.setName("Germany");
+ s.persist(country);
+ tx.commit();
+ s.close();
+
+ try {
+ s = openSession();
+ tx = s.beginTransaction();
+ Country germany = (Country) s.get(Country.class, country.getId());
+ assertNotNull(germany);
+ germany.setName("France");
+ s.save(germany);
+ s.delete(germany);
+ tx.commit();
+ s.close();
+// fail();
+ } catch (Exception e) {
+ log.debug("success");
+ }
+ }
+
+ public void testImmutableEntityWithMappingFile() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ CountryHbm country = new CountryHbm();
+ country.setName("Germany");
+ s.persist(country);
+ tx.commit();
+ s.close();
+
+ try {
+ s = openSession();
+ tx = s.beginTransaction();
+ CountryHbm germany = (CountryHbm) s.get(CountryHbm.class, country.getId());
+ assertNotNull(germany);
+ germany.setName("France");
+ s.save(germany);
+ s.delete(germany);
+ tx.commit();
+ s.close();
+// fail();
+ } catch (Exception e) {
+ log.debug("success");
+ }
+ }
+
+ /**
+ * @see org.hibernate.test.annotations.TestCase#getMappings()
+ */
+ protected Class[] getMappings() {
+ return new Class[] { Country.class };
+ }
+
+ @Override
+ protected String[] getXmlFiles() {
+ return new
String[]{"org/hibernate/test/annotations/immutable/Country.hbm.xml"};
+ }
+}
Property changes on:
annotations/trunk/src/test/org/hibernate/test/annotations/immutable/ImmutableTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Show replies by date