Cannot get unfetched attribute [speaker] from detached object com.company.planner.entity.Session

Hello, I am new on cuba, and i may be a litle lost, so please be patient. I found in the forum a lot of this problem but not a solution to me. I am trying to make a test for the rescheduler in planner session, but for some reason when i get the session from the database the speaker is not matching. I must being missing something but as I say I am new.

public class SessionServiceTest {
@RegisterExtension
public static PlannerTestContainer testContainer = PlannerTestContainer.Common.INSTANCE;

private static SessionService sessionService;
private static DataManager dataManager;

private Session mySession;


@BeforeAll
public  static  void  setupEnviroment(){
    sessionService = AppBeans.get(SessionService.class);
    dataManager = AppBeans.get(DataManager.class);
}

@BeforeEach
public void loadSession(){
   mySession = dataManager.loadValue(
           "select e from planner_Session e",Session.class).one();
}

@Test
public void rescheduleTest_week(){
    LocalDateTime initialDate = mySession.getStartDate();
    LocalDateTime newDate = initialDate.plusDays(7);
    Session newSession = sessionService.rescheduleSession(mySession, newDate);
    assertThat(newSession.getStartDate()).isEqualTo(initialDate.plusDays(7));
    sessionService.rescheduleSession(mySession, initialDate);
}

}

The full error is this:

et unfetched attribute [speaker] from detached object com.company.planner.entity.Session-749f3627-175f-84d1-b766-d115c7f1c230 [detached].
com.haulmont.cuba.core.global.RemoteException:

java.lang.IllegalStateException: Cannot get unfetched attribute [speaker] from detached object com.company.planner.entity.Session-749f3627-175f-84d1-b766-d115c7f1c230 [detached].
at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(ServiceInterceptor.java:96)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy160.rescheduleSession(Unknown Source)
at com.company.planner.service.SessionServiceTest.rescheduleTest_week(SessionServiceTest.java:45)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:102)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:82)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:78)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:834)

Hi,
Problem “unfectched attribute” generally will be produced because the view used on the data container doesn’t have this attribute included.

I hope this was useful.

Regards

Hi,

It has it, for what i know:

<view entity="planner_Session" name="session-view" extends="_local">
        <property name="speaker" view="_minimal"/>
        <property name="endDate"/>
    </view>

But is also true that speaker is a entity and it is a many to one relation. And i dont have a view for speaker, how should I create a view for speaker and where to have this working?.

Regards

Hi,
First thing I would do is to check in that “session-view” has access to “speaker”.
You don’t have to create another view for speaker, only checking that “session-view” has access to it.

Regards,

Hi,

How can i do that?

Regards.

Hi,
You have to go to project explorer and expand Session entity to show all views created for this entity. Image below is an example of one of my projects with an a view called “solicitud-view-edit”:
View tree

Then you have to click the view item "session-view"to show all attributes accessible for it and check in if this view has checked “speaker” attribute. Image below is an example:
view edit

I hope it helps you.

Regards.
Xavier

Well I already had this donne, and its not working i try to create a full view for speaker and use it but nothing. The onli thing may be a problem of my test.

package com.company.planner.service;

import com.company.planner.PlannerTestContainer;
import com.company.planner.entity.Session;
import com.company.planner.entity.Speaker;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.DataManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.LocalDateTime;

public class SessionServiceTest {
@RegisterExtension
public static PlannerTestContainer testContainer = PlannerTestContainer.Common.INSTANCE;

private static SessionService sessionService;
private static DataManager dataManager;

private Session mySession;


@BeforeAll
public  static  void  setupEnviroment(){
    sessionService = AppBeans.get(SessionService.class);
    dataManager = AppBeans.get(DataManager.class);
}

@BeforeEach
public void loadSession(){
   mySession = dataManager.loadValue(
           "select e from planner_Session e",Session.class).one();
}

@Test
public void rescheduleTest_week(){
    LocalDateTime initialDate = mySession.getStartDate();
    LocalDateTime newDate = initialDate.plusDays(7);
    Session newSession = sessionService.rescheduleSession(mySession, newDate);
    assertThat(newSession.getStartDate()).isEqualTo(initialDate.plusDays(7));
    //volver a dejar como estaba
    sessionService.rescheduleSession(mySession, initialDate);
}

}

Hi,
You should add the view your want to use to retrieve the session entity with datamanager on the following code:

           "select e from planner_Session e",Session.class).one();

like this exemple code:

return dataManager.load(DetallPacking.class)
                .query("select e from magatzem_DetallPacking e where e.pacCteCd = :numcte and e.pacCteLnCd = :numln and e.pacDtLnDt = :numlndt")
                .view("detallPacking-view")
                .parameter("numcte", ctecd)
                .parameter("numln", ctelncd)
                .parameter("numlndt", lndtpck)
                .one();

Good luck!

Hi,
Xavier thank you for your effort, i try to get the data like that:

   @BeforeEach
    public void loadSession(){
        String tp = "python";
       mySession = dataManager.load(Session.class)
               .query("select e from planner_Session e",Session.class)
               .view("session-view").one();
    }

But I am getting a error that has not sense, sinces I am not using parametersn and I dont want to, I just want to take the first row in that table.

Parameter '_p1' is not used in the query
com.haulmont.cuba.core.global.DevelopmentException: Parameter '_p1' is not used in the query

The way I was doing it at least i got the Session, just the speaker parameter was not working, and I really don’t understand why its working with the app, and is not working with the Test.

Regards.

Hi,

Session.class that you pass to the query method is considered as a parameter, see the method definition:

Screenshot 2020-08-17 at 11.07.45

Since the query has no parameter placeholder, you get an exception.

Regards,
Gleb

Thank you both, I finally solve the problem whit this.