diff --git a/pom.xml b/pom.xml
index 712a37ed..bce65b91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
UTF-8
java:openejb/Resource/My DataSource
- false
+ true
diff --git a/src/main/java/com/commafeed/backend/dao/FeedEntryService.java b/src/main/java/com/commafeed/backend/dao/FeedEntryService.java
index 63b33a2c..4b2337cd 100644
--- a/src/main/java/com/commafeed/backend/dao/FeedEntryService.java
+++ b/src/main/java/com/commafeed/backend/dao/FeedEntryService.java
@@ -3,6 +3,7 @@ package com.commafeed.backend.dao;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;
+import java.util.Set;
import javax.ejb.Stateless;
import javax.inject.Inject;
@@ -21,6 +22,7 @@ import com.commafeed.backend.model.extended.FeedEntryWithStatus;
import com.commafeed.frontend.utils.ModelFactory.MF;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
@Stateless
@SuppressWarnings("serial")
@@ -188,13 +190,14 @@ public class FeedEntryService extends GenericDAO {
@SuppressWarnings("rawtypes")
private List buildList(List list) {
- List result = Lists.newArrayList();
+ Set result = Sets.newLinkedHashSet();
for (Object object : list) {
Object[] array = (Object[]) object;
FeedEntry entry = (FeedEntry) array[0];
FeedEntryStatus status = (FeedEntryStatus) array[1];
- result.add(new FeedEntryWithStatus(entry, status));
+ FeedEntryWithStatus fews = new FeedEntryWithStatus(entry, status);
+ result.add(fews);
}
- return result;
+ return Lists.newArrayList(result);
}
}
diff --git a/src/main/java/com/commafeed/backend/model/FeedEntry.java b/src/main/java/com/commafeed/backend/model/FeedEntry.java
index 32489886..98a60470 100644
--- a/src/main/java/com/commafeed/backend/model/FeedEntry.java
+++ b/src/main/java/com/commafeed/backend/model/FeedEntry.java
@@ -5,7 +5,6 @@ import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
@@ -27,7 +26,7 @@ public class FeedEntry extends AbstractModel {
@Column(length = 2048, nullable = false)
private String guid;
- @ManyToMany(fetch = FetchType.EAGER)
+ @ManyToMany
@JoinTable(name = "FEED_FEEDENTRIES", joinColumns = { @JoinColumn(name = "FEED_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "FEEDENTRY_ID", nullable = false, updatable = false) })
private Set feeds = Sets.newHashSet();
diff --git a/src/main/java/com/commafeed/backend/model/extended/FeedEntryWithStatus.java b/src/main/java/com/commafeed/backend/model/extended/FeedEntryWithStatus.java
index b5a14f34..f1199574 100644
--- a/src/main/java/com/commafeed/backend/model/extended/FeedEntryWithStatus.java
+++ b/src/main/java/com/commafeed/backend/model/extended/FeedEntryWithStatus.java
@@ -1,5 +1,8 @@
package com.commafeed.backend.model.extended;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryStatus;
@@ -12,6 +15,31 @@ public class FeedEntryWithStatus {
this.status = status;
}
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder(17, 37).append(entry.getId())
+ .append(status == null ? null : status.getId()).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj.getClass() != getClass()) {
+ return false;
+ }
+ FeedEntryWithStatus rhs = (FeedEntryWithStatus) obj;
+ return new EqualsBuilder()
+ .append(status == null ? null : status.getId(),
+ rhs.status == null ? null : rhs.status.getId())
+ .append(entry.getId(), rhs.entry.getId()).isEquals();
+
+ }
+
public FeedEntry getEntry() {
return entry;
}
diff --git a/src/main/resources/META-INF/orm.xml b/src/main/resources/META-INF/orm.xml
index 66308fc8..5c112453 100644
--- a/src/main/resources/META-INF/orm.xml
+++ b/src/main/resources/META-INF/orm.xml
@@ -10,34 +10,34 @@
- select e from FeedEntry e where e.guid in (:guids) order by e.updated desc
+ select DISTINCT e from FeedEntry e LEFT JOIN FETCH e.feeds where e.guid in (:guids) order by e.updated desc
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds) and not exists (select s3 from FeedEntryStatus s3 where s3.entry = e and s3.user =:user and s3.read=true) order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) LEFT JOIN FETCH e.feeds where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds) and not exists (select s3 from FeedEntryStatus s3 where s3.entry = e and s3.user =:user and s3.read=true) order by e.updated desc
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds) order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId)LEFT JOIN FETCH e.feeds where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds) order by e.updated desc
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where :feed member of e.feeds and not exists (select s2 from FeedEntryStatus s2 where s2.entry=e and s2.user.id=:userId and s2.read=true) order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) LEFT JOIN FETCH e.feeds where :feed member of e.feeds and not exists (select s2 from FeedEntryStatus s2 where s2.entry=e and s2.user.id=:userId and s2.read=true) order by e.updated desc
select count(e) from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where :feed member of e.feeds and not exists (select s2 from FeedEntryStatus s2 where s2.entry=e and s2.user.id=:userId and s2.read=true)
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where :feed member of e.feeds order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) LEFT JOIN FETCH e.feeds where :feed member of e.feeds order by e.updated desc
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds and s2.category in (:categories) ) and not exists (select s3 from FeedEntryStatus s3 where s3.entry = e and s3.user =:user and s3.read=true) order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) LEFT JOIN FETCH e.feeds where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds and s2.category in (:categories) ) and not exists (select s3 from FeedEntryStatus s3 where s3.entry = e and s3.user =:user and s3.read=true) order by e.updated desc
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds and s2.category in (:categories) ) order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) LEFT JOIN FETCH e.feeds where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds and s2.category in (:categories) ) order by e.updated desc
- select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds) and (lower(e.content) like :keywords or lower(e.title) like :keywords) order by e.updated desc
+ select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) LEFT JOIN FETCH e.feeds where exists (select s2 from FeedSubscription s2 where s2.user=:user and s2.feed member of e.feeds) and (lower(e.content) like :keywords or lower(e.title) like :keywords) order by e.updated desc
\ No newline at end of file