Есть 4 сущности:
MainFlows:
@Entity
@Table(name = "MainFlows")
public class MainFlows implements Serializable {
private BigInteger id;
private String planFact;
private String fileName;
private Date settlementDate;
private float summa;
private String orgName;
private String inn;
private String account;
private String purposePayment;
private String payment;
private UnderFacilities underFacilities;
@ManyToOne
@JoinColumn(name = "UnderFacilityId")
public UnderFacilities getUnderFacilities(){
return underFacilities;
}
public void setUnderFacilities(UnderFacilities underFacilities){
this.underFacilities = underFacilities;
}
}
Facilityes:
@Entity
@Table(name = "FACILITYES")
public class Facilityes implements Serializable {
private BigInteger id;
private String facility;
private String city;
private String address;
private Users manager;
private Set<Users> investors;
private List<UnderFacilities> underFacilities;
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinColumn(name = "MANAGER_ID", referencedColumnName = "id")
public Users getManager(){
return manager;
}
public void setManager(Users manager){
this.manager = manager;
}
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "USERS_FACILITYES",
joinColumns = { @JoinColumn(name = "FACILITY_ID", referencedColumnName = "id") },
inverseJoinColumns = @JoinColumn(name = "RENTOR_INVESTORS_ID", referencedColumnName = "id"))
public Set<Users> getInvestors(){
return investors;
}
public void setInvestors(Set<Users> investors){
this.investors = investors;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "facility")
public List<UnderFacilities> getUnderFacilities(){
return underFacilities;
}
public void setUnderFacilities(List<UnderFacilities> underFacilities){
this.underFacilities = underFacilities;
}
}
UnderFacilities:
@Entity
@Table(name = "UnderFacilities")
public class UnderFacilities implements Serializable {
private BigInteger id;
private BigInteger facilityId;
private String underFacility;
private Facilityes facility;
private List<MainFlows> mainFlows;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FacilityId")
public Facilityes getFacility(){
return facility;
}
public void setFacility(Facilityes facility){
this.facility = facility;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public BigInteger getId(){
return id;
}
public void setId(BigInteger id){
this.id = id;
}
@Column(name = "FacilityId", insertable = false, updatable = false)
public BigInteger getFacilityId(){
return facilityId;
}
public void setFacilityId(BigInteger facilityId){
this.facilityId = facilityId;
}
@Column(name = "UnderFacility")
public String getUnderFacility(){
return underFacility;
}
public void setUnderFacility(String underFacility){
this.underFacility = underFacility;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "underFacilities")
public List<MainFlows> getMainFlows(){
return mainFlows;
}
public void setMainFlows(List<MainFlows> mainFlows){
this.mainFlows = mainFlows;
}
}
Users:
@Entity
@Table(name = "USERS")
public class Users implements Serializable{
private BigInteger id;
private String login;
private BigInteger stuffId;
private String password;
private String lastName;
private String first_name;
private String middle_name;
private String email;
private int office_id;
private String state;
private Set<Roles> roles;
private Stuffs userStuff;
private MailingGroups mailingGroups;
private Set<Facilityes> facilityes;
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinColumn(name = "stuffId", referencedColumnName = "id")
public Stuffs getUserStuff(){
return userStuff;
}
public void setUserStuff(Stuffs userStuff){
this.userStuff = userStuff;
}
@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinColumn(name = "MailingGroupId", referencedColumnName = "id")
public MailingGroups getMailingGroups(){
return mailingGroups;
}
public void setMailingGroups(MailingGroups mailingGroups){
this.mailingGroups = mailingGroups;
}
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "USERS_FACILITYES",
joinColumns = { @JoinColumn(name = "RENTOR_INVESTORS_ID", referencedColumnName = "id") },
inverseJoinColumns = @JoinColumn(name = "FACILITY_ID", referencedColumnName = "id"))
public Set<Facilityes> getFacilityes(){
return facilityes;
}
public void setFacilityes(Set<Facilityes> facilityes){
this.facilityes = facilityes;
}
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
@JoinTable(name = "USERS_ROLES",
joinColumns = { @JoinColumn(name = "user_id") },
inverseJoinColumns = @JoinColumn(name = "role_id")
)
public Set<Roles> getRoles() {
return roles;
}
public void setRoles(Set<Roles> roles) {
this.roles = roles;
}
}
Пытаюсь достать сущность Users
из MainFlows
, но что-то не получается, не выгружается Facilityes
и Users
, соответственно получаю lazy exception
:
public List<MainFlows> findAllWithCriteriaApi(){
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MainFlows> mainFlowsCriteriaQuery = cb.createQuery(MainFlows.class);
Root<MainFlows> mainFlowsRoot = mainFlowsCriteriaQuery.from(MainFlows.class);
CriteriaQuery<UnderFacilities> underFacilitiesCriteriaQuery = cb.createQuery(UnderFacilities.class);
Root<UnderFacilities> underFacilitiesRoot = underFacilitiesCriteriaQuery.from(UnderFacilities.class);
CriteriaQuery<Facilityes> facilityesCriteriaQuery = cb.createQuery(Facilityes.class);
Root<Facilityes> facilityesRoot = facilityesCriteriaQuery.from(Facilityes.class);
Fetch<MainFlows, UnderFacilities> mainFlowsUnderFacilitiesJoin = mainFlowsRoot.fetch(MainFlows_.underFacilities, JoinType.LEFT);
Fetch<UnderFacilities, Facilityes> underFacilitiesFacilityesJoin = underFacilitiesRoot.fetch(UnderFacilities_.facility, JoinType.LEFT);
Fetch<Facilityes, Users> facilityesUsersJoin = facilityesRoot.fetch(Facilityes_.investors, JoinType.LEFT);
mainFlowsCriteriaQuery.select(mainFlowsRoot);
List<MainFlows> mainFlowsList = em.createQuery(mainFlowsCriteriaQuery).getResultList();
return em.createQuery(mainFlowsCriteriaQuery).getResultList();
}
Как указать, что мне надо вытащить связанные сущности?
UPD:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:286) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at com.art.model.Facilityes_$$_jvst68f_8.getInvestors(Facilityes_$$_jvst68f_8.java) ~[classes/:na]
at com.art.controllers.InvestorsFlowsController.lambda$viewiFlows2$0(InvestorsFlowsController.java:101) ~[classes/:na]
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) ~[na:1.8.0_144]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) ~[na:1.8.0_144]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_144]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_144]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_144]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_144]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_144]
at com.art.controllers.InvestorsFlowsController.viewiFlows2(InvestorsFlowsController.java:102) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) ~[spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) [spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) [spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) [spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.0.M26]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.0.M26]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.0.M26]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:158) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) [spring-security-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.0.M26]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:9.0.0.M26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [catalina.jar:9.0.0.M26]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651) [catalina.jar:9.0.0.M26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:9.0.0.M26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [catalina.jar:9.0.0.M26]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498) [tomcat-coyote.jar:9.0.0.M26]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.0.M26]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796) [tomcat-coyote.jar:9.0.0.M26]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1374) [tomcat-coyote.jar:9.0.0.M26]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.0.M26]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.0.M26]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Решения нашёл 2. 1. Добавить следующие строки:
public List<MainFlows> findAllWithCriteriaApi(){
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MainFlows> mainFlowsCriteriaQuery = cb.createQuery(MainFlows.class);
Root<MainFlows> mainFlowsRoot = mainFlowsCriteriaQuery.from(MainFlows.class);
CriteriaQuery<UnderFacilities> underFacilitiesCriteriaQuery = cb.createQuery(UnderFacilities.class);
Root<UnderFacilities> underFacilitiesRoot = underFacilitiesCriteriaQuery.from(UnderFacilities.class);
CriteriaQuery<Facilityes> facilityesCriteriaQuery = cb.createQuery(Facilityes.class);
Root<Facilityes> facilityesRoot = facilityesCriteriaQuery.from(Facilityes.class);
Fetch<MainFlows, UnderFacilities> mainFlowsUnderFacilitiesJoin = mainFlowsRoot.fetch(MainFlows_.underFacilities, JoinType.LEFT);
Fetch<UnderFacilities, Facilityes> underFacilitiesFacilityesJoin = underFacilitiesRoot.fetch(UnderFacilities_.facility, JoinType.LEFT);
Fetch<Facilityes, Users> facilityesUsersJoin = facilityesRoot.fetch(Facilityes_.investors, JoinType.LEFT);
mainFlowsCriteriaQuery.select(mainFlowsRoot);
List<MainFlows> mainFlowsList = em.createQuery(mainFlowsCriteriaQuery).getResultList();
//Добавлено
mainFlowsList.forEach(mf -> mf.getUnderFacilities().getFacility().getInvestors().size());
//
return em.createQuery(mainFlowsCriteriaQuery).getResultList();
}
Но что-то мне подсказывает, что это некий "костыль".
Переделал метод на следующий:
public List findAllWithCriteriaApi(){ CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MainFlows> mainFlowsCriteriaQuery = cb.createQuery(MainFlows.class);
Root<MainFlows> mainFlowsRoot = mainFlowsCriteriaQuery.from(MainFlows.class);
mainFlowsRoot.fetch(MainFlows_.underFacilities, JoinType.LEFT)
.fetch(UnderFacilities_.facility, JoinType.LEFT)
.fetch(Facilityes_.investors, JoinType.LEFT);
mainFlowsCriteriaQuery.select(mainFlowsRoot).distinct(true);
return em.createQuery(mainFlowsCriteriaQuery).getResultList();
}
Тут приходится использовать distinct
иначе количество записей возрастает многократно. Буду признателен за комментарии к обоим решениям или если это не оптимальное решение и можно как-то изящней сделать, то тоже буду благодарен.
Виртуальный выделенный сервер (VDS) становится отличным выбором
Возможно вопрос неправильный и я бы его не задал, если бы не нужно было через три дня сдавать задание - crud-приложение с пагинациейПо условию...
При открытии файла XML в редакторе Eclipse последний выводит его одной длинной строкойПосле форматирования(в ручную или с Ctrl+Shift+F, не важно) я не могу...