[hibernate-commits] Hibernate SVN: r20825 - search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Oct 13 09:35:29 EDT 2010


Author: epbernard
Date: 2010-10-13 09:35:28 -0400 (Wed, 13 Oct 2010)
New Revision: 20825

Added:
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java
Modified:
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java
Log:
HSEARCH-577 IllegalArgumentException when using a @Proxy and deleting a lazy proxy

Adding test to reproduce the issue

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Comment.java	2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,84 @@
+package org.hibernate.search.test.proxy;
+
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.CascadeType;
+import org.hibernate.annotations.Proxy;
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Tom Kuo
+ */
+ at Entity
+ at Table(name = "comment")
+ at Proxy(proxyClass = IComment.class)
+public class Comment implements IComment {
+
+	private Integer id;
+	private IProfile parent;
+	private String name;
+	private IComment root;
+	private List<IComment> replies = new ArrayList<IComment>();
+
+	@Id
+	@Column(name = "commentid")
+	public Integer getId() {
+		return id;
+	}
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	@ManyToOne(targetEntity = Profile.class, fetch = FetchType.LAZY)
+	@JoinColumn(name = "profileid")
+	@ContainedIn
+    public IProfile getProfile() {
+		if (parent == null && getRootComment() != null) {
+			return getRootComment().getProfile();
+		}
+	    return parent;
+    }
+    public void setProfile(IProfile p) {
+    	this.parent = p;
+    }
+
+	@Column(name = "content")
+	@Field(name = "content")
+	public String getContent() {
+		return name;
+	}
+	public void setContent(String name) {
+		this.name = name;
+	}
+
+	@ManyToOne(targetEntity = Comment.class, fetch = FetchType.LAZY)
+	@JoinColumn(name = "rootid")
+	public IComment getRootComment() {
+		return root;
+	}
+	public void setRootComment(IComment root) {
+		this.root = root;
+	}
+
+	@OneToMany(targetEntity = Comment.class, mappedBy = "rootComment", fetch = FetchType.LAZY)
+	@Cascade(CascadeType.DELETE)
+	public List<IComment> getReplies() {
+		return replies;
+	}
+
+	public void setReplies(List<IComment> replies) {
+		this.replies = replies;
+	}
+}

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IComment.java	2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,31 @@
+package org.hibernate.search.test.proxy;
+
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Tom Kuo
+ */
+public interface IComment {
+
+	public Integer getId();
+
+	public void setId(Integer id);
+
+	public IProfile getProfile();
+
+	public void setProfile(IProfile p);
+
+	public String getContent();
+
+	public void setContent(String name);
+
+	public IComment getRootComment();
+
+	public void setRootComment(IComment root);
+
+	public List<IComment> getReplies();
+
+	public void setReplies(List<IComment> replies);
+
+}

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/IProfile.java	2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,18 @@
+package org.hibernate.search.test.proxy;
+
+import java.util.Set;
+
+/**
+ * @author Emmanuel Bernard
+ * @author Tom Kuo
+ */
+public interface IProfile {
+
+	public Integer getId();
+
+	public void setId(Integer id);
+
+	public Set<IComment> getComments();
+
+	public void setComments(Set<IComment> c);
+}

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/Profile.java	2010-10-13 13:35:28 UTC (rev 20825)
@@ -0,0 +1,43 @@
+package org.hibernate.search.test.proxy;
+
+import org.hibernate.annotations.Proxy;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import java.util.Set;
+
+ at Entity
+ at Indexed
+ at Table(name = "profile")
+ at Proxy(proxyClass = IProfile.class)
+public class Profile implements IProfile {
+
+	private Integer id;
+	private Set<IComment> comments;
+
+	@Id
+	@DocumentId
+	@Column(name = "profileid")
+	public Integer getId() {
+		return id;
+	}
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	@OneToMany(targetEntity = Comment.class, mappedBy = "profile")
+	@IndexedEmbedded(targetElement = Comment.class)
+    public Set<IComment> getComments() {
+	    return comments;
+    }
+    public void setComments(Set<IComment> c) {
+    	this.comments = c;
+    }
+
+}

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java	2010-10-13 13:19:30 UTC (rev 20824)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/proxy/ProxyTest.java	2010-10-13 13:35:28 UTC (rev 20825)
@@ -29,6 +29,7 @@
 import org.hibernate.Session;
 import org.hibernate.Transaction;
 import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.testing.junit.FailureExpected;
 
 
 /**
@@ -63,8 +64,57 @@
 		session.close();
 	}
 
+	@FailureExpected(jiraKey = "HSEARCH-577")
+	public void testDeteleProxy() throws Exception {
+		createTestData();
+
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
+		IComment c = (IComment)s.get(Comment.class, 2);
+		s.delete(c);
+		tx.commit();
+		s.close();
+	}
+
+	public void createTestData() {
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
+		IProfile p = new Profile();
+		p.setId(1);
+		s.save(p);
+
+		IComment c1 = new Comment();
+		c1.setId(2);
+		c1.setProfile((IProfile)s.get(Profile.class, 1));
+		c1.setContent("c1");
+		c1.setRootComment(null);
+		s.save(c1);
+
+		IComment c2 = new Comment();
+		c2.setId(3);
+		c2.setProfile((IProfile)s.get(Profile.class, 1));
+		c2.setContent("c2");
+		c2.setRootComment(c1);
+		s.save(c2);
+
+		IComment c3 = new Comment();
+		c3.setId(4);
+		c3.setProfile((IProfile)s.get(Profile.class, 1));
+		c3.setContent("c3");
+		c3.setRootComment(c1);
+		s.save(c3);
+
+		tx.commit();
+		s.close();
+	}
+
 	@Override
 	protected Class<?>[] getAnnotatedClasses() {
-		return new Class[] { Book.class, Author.class };
+		return new Class[] {
+				Book.class,
+				Author.class,
+				Comment.class,
+				Profile.class
+		};
 	}
 }



More information about the hibernate-commits mailing list