[BAEL-4056] Guide to MultipleBagFetchException (#10304)
* Removes DummyEntity * Uses Artist Entity instead of DummyEntity
This commit is contained in:
parent
2700958ec0
commit
bc281bde2f
|
@ -1,43 +0,0 @@
|
||||||
package com.baeldung.jpa.multiplebagfetchexception;
|
|
||||||
|
|
||||||
import javax.persistence.ElementCollection;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
class DummyEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
private List<String> collection1;
|
|
||||||
|
|
||||||
@ElementCollection
|
|
||||||
private List<String> collection2;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o)
|
|
||||||
return true;
|
|
||||||
if (o == null || getClass() != o.getClass())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
DummyEntity that = (DummyEntity) o;
|
|
||||||
|
|
||||||
return Objects.equals(id, that.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return id != null ? id.hashCode() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DummyEntity() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -57,7 +57,6 @@
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
<persistence-unit name="jpa-h2-multiple-bag-fetch-exception">
|
<persistence-unit name="jpa-h2-multiple-bag-fetch-exception">
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
<class>com.baeldung.jpa.multiplebagfetchexception.DummyEntity</class>
|
|
||||||
<class>com.baeldung.jpa.multiplebagfetchexception.Album</class>
|
<class>com.baeldung.jpa.multiplebagfetchexception.Album</class>
|
||||||
<class>com.baeldung.jpa.multiplebagfetchexception.Song</class>
|
<class>com.baeldung.jpa.multiplebagfetchexception.Song</class>
|
||||||
<class>com.baeldung.jpa.multiplebagfetchexception.User</class>
|
<class>com.baeldung.jpa.multiplebagfetchexception.User</class>
|
||||||
|
|
|
@ -29,9 +29,9 @@ public class MultipleBagFetchExceptionIntegrationTest {
|
||||||
public void whenFetchingMoreThanOneBag_thenThrowAnException() {
|
public void whenFetchingMoreThanOneBag_thenThrowAnException() {
|
||||||
IllegalArgumentException exception =
|
IllegalArgumentException exception =
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
String jpql = "SELECT dummy FROM DummyEntity dummy "
|
String jpql = "SELECT artist FROM Artist artist "
|
||||||
+ "JOIN FETCH dummy.collection1 "
|
+ "JOIN FETCH artist.songs "
|
||||||
+ "JOIN FETCH dummy.collection2 ";
|
+ "JOIN FETCH artist.offers ";
|
||||||
|
|
||||||
entityManager.createQuery(jpql);
|
entityManager.createQuery(jpql);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue