[hibernate-commits] Hibernate SVN: r14397 - in annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement: indexedCollection and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Mar 6 16:40:40 EST 2008


Author: epbernard
Date: 2008-03-06 16:40:39 -0500 (Thu, 06 Mar 2008)
New Revision: 14397

Added:
   annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/
   annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Contact.java
   annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/IndexedCollectionOfElementsTest.java
   annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java
Log:
ANN-701 Added test

Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Contact.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Contact.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Contact.java	2008-03-06 21:40:39 UTC (rev 14397)
@@ -0,0 +1,20 @@
+//$
+package org.hibernate.test.annotations.collectionelement.indexedCollection;
+
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Embeddable
+public class Contact {
+	private String name;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+}

Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/IndexedCollectionOfElementsTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/IndexedCollectionOfElementsTest.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/IndexedCollectionOfElementsTest.java	2008-03-06 21:40:39 UTC (rev 14397)
@@ -0,0 +1,32 @@
+//$
+package org.hibernate.test.annotations.collectionelement.indexedCollection;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.Session;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class IndexedCollectionOfElementsTest extends TestCase {
+
+	public void testIndexedCollectionOfElements() throws Exception {
+		Sale sale = new Sale();
+		Contact contact = new Contact();
+		contact.setName( "Emmanuel" );
+		sale.getContacts().add(contact);
+		Session s = openSession(  );
+		s.getTransaction().begin();
+		s.save( sale );
+		s.flush();
+		s.get( Sale.class, sale.getId() );
+		assertEquals( 1, sale.getContacts().size() );
+		s.getTransaction().rollback();
+		s.close();
+	}
+
+	protected Class[] getMappings() {
+		return new Class[] {
+				Sale.class
+		};
+	}
+}

Added: annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/collectionelement/indexedCollection/Sale.java	2008-03-06 21:40:39 UTC (rev 14397)
@@ -0,0 +1,51 @@
+//$
+package org.hibernate.test.annotations.collectionelement.indexedCollection;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.Column;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.CollectionId;
+import org.hibernate.annotations.GenericGenerator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+ at GenericGenerator(name="increment", strategy = "increment")
+public class Sale {
+	@Id @GeneratedValue private Integer id;
+
+	@CollectionOfElements
+    @JoinTable(
+        name = "contact",
+        joinColumns = @JoinColumn(name = "n_key_person"))
+    @CollectionId(
+        columns = @Column(name = "n_key_contact"),
+        type = @Type(type = "long"),
+        generator = "increment" ) 
+	private List<Contact> contacts = new ArrayList<Contact>();
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public List<Contact> getContacts() {
+		return contacts;
+	}
+
+	public void setContacts(List<Contact> contacts) {
+		this.contacts = contacts;
+	}
+}




More information about the hibernate-commits mailing list