1 2 3 4 5 Previous Next 70 Replies Latest reply on Apr 20, 2006 3:38 PM by clebert.suconic Go to original post
      • 30. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4

        Clebert, all your investigations are highly appreciated!

        • 31. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
          ejb3workshop

          I suggest you check the classpath. In particular take a look at the ejb3 installation guide:


          Because you patched 4.0.3SP1, the client jars in the jboss-4.0.3SP1/client directory will be invalid. Build your client classpath from:

          1. jboss-4.0.3SP1/lib
          2. jboss-4.0.3SP1/server/all/lib
          3. jboss-4.0.3SP1/server/all/deploy/ejb3.deployer
          4. jboss-4.0.3SP1/server/all/deploy/jboss-aop-jdk50.deployer


          • 32. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4

            I am doing that as you can see in the test case attached to http://jira.jboss.com/jira/browse/EJBTHREE-440

            • 33. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
              phon

              i also have checked the classpath thoroughly.

              but apart from that, it works fine in a java web strat environment with exactly the same classpath..

              • 34. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4

                phon, the "classpath" you pass to JWS may be the same. But the classloader structure in JWS is inherently different from a standalone application.

                • 35. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                  ejb3workshop

                  Maybe take a look at :

                  http://www.jboss.com/index.html?module=bb&op=viewtopic&t=76791

                  Could you please post some of you code which shows the relationship mapping.
                  Alex

                  • 36. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4

                    similar issue

                    trying to serialize an Object from ejb3 layer to web layer (servlet).

                    did not happend on 4.0.3sp1 and before (EJBRC3).

                    ------------------------------

                    type Exception report

                    message

                    description The server encountered an internal error () that prevented it from fulfilling this request.

                    exception

                    java.lang.ClassCastException: org.jboss.ejb3.stateless.StatelessBeanContext
                    org.jboss.ejb3.injection.ExtendedPersistenceContextInjector.inject(ExtendedPersistenceContextInjector.java:57)
                    org.jboss.ejb3.injection.ExtendedPersistenceContextInjector.inject(ExtendedPersistenceContextInjector.java:52)
                    org.jboss.ejb3.AbstractPool.create(AbstractPool.java:88)
                    org.jboss.ejb3.ThreadlocalPool.get(ThreadlocalPool.java:48)
                    org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:51)
                    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                    org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
                    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                    org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
                    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                    org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
                    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                    org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:219)
                    org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:55)
                    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                    org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
                    $Proxy407.fetchContentItemType(Unknown Source)
                    com.foo.boo.web.generic.TestServlet.doPost(TestServlet.java:36)
                    com.foo.boo.web.generic.TestServlet.doGet(TestServlet.java:20)
                    javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                    javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


                    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.

                    • 37. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4

                       

                      "gduan2000" wrote:
                      similar issue

                      trying to serialize an Object from ejb3 layer to web layer (servlet).

                      did not happend on 4.0.3sp1 and before (EJBRC3).

                      ------------------------------

                      type Exception report

                      message

                      description The server encountered an internal error () that prevented it from fulfilling this request.

                      exception

                      java.lang.ClassCastException: org.jboss.ejb3.stateless.StatelessBeanContext
                      org.jboss.ejb3.injection.ExtendedPersistenceContextInjector.inject(ExtendedPersistenceContextInjector.java:57)
                      org.jboss.ejb3.injection.ExtendedPersistenceContextInjector.


                      Well, I found the fix for my issue. The class I was trying to serialize had a field like this:
                      private SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");


                      It was OK in 4.0.3SP1, but since I switch to EJB3.0RC5, It stopped working. I spend hours searching and testing. Eventually I found the fix: just change it to static final.
                      private static final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");


                      I don't know if this is a JBoss issue or what it is supposed to be. Can someone explain?

                      Hope this might help someone who is searching for an answer...

                      g

                      • 38. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                        ejb3workshop

                        I think the problem is with how exceptions are handled on the remote client side which originate form the server. Maybe somebody better suited could shed some light on this issue. Something since RC4 has changed in the way exceptions are passed.

                        Alex

                        • 39. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                          jwynett

                          I just upgraded to 4.0.4RC1 and EJB3 RC5 and have a very similar problem although with different stack trace. After tracing through some code it seems to fail on the HibernateProxy and is fixed by changing lazy relationships to eager. It seems to occur on certain ManyToOne relationships and only on a particular module of mine that has a more complicated relationship structure.

                          Little by little I am switching relationships from Lazy to Eager to solve the EnhancerByCGLib probs as I see them and I'm worried pretty soon I'll have to load the entire relationship structure every time.

                          The actual line the failure occurs on is in org.jboss.serial.persister.ClassReferencePersister and it is as follows:

                          Class clazz = (Class)obj;
                          


                          Here is the full stacktrace:
                          javax.ejb.EJBException: java.lang.reflect.UndeclaredThrowableException
                           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
                           at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
                           at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at net.lgsystems.jboss.security.LgsRoleBasedAuthorizationInterceptor.invoke(LgsRoleBasedAuthorizationInterceptor.java:134)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:178)
                           at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:74)
                           at $Proxy276.addDevicePolicyForGroup(Unknown Source)
                           at net.lgsystems.policy.test.DevicePolicyMgrTest.testGroupOverrideGroupWithSamePolicyType(DevicePolicyMgrTest.java:102)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at junit.framework.TestCase.runTest(TestCase.java:154)
                           at junit.framework.TestCase.runBare(TestCase.java:127)
                           at junit.framework.TestResult$1.protect(TestResult.java:106)
                           at junit.framework.TestResult.runProtected(TestResult.java:124)
                           at junit.framework.TestResult.run(TestResult.java:109)
                           at junit.framework.TestCase.run(TestCase.java:118)
                           at junit.framework.TestSuite.runTest(TestSuite.java:208)
                           at junit.framework.TestSuite.run(TestSuite.java:203)
                           at net.lgsystems.util.testutil.TestServiceBean.executeTest(TestServiceBean.java:86)
                           at sun.reflect.GeneratedMethodAccessor617.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
                           at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:66)
                           at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:111)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:219)
                           at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
                           at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
                           at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:580)
                           at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:450)
                           at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:290)
                           at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:330)
                           at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:202)
                          Caused by: java.lang.reflect.UndeclaredThrowableException
                           at $Proxy273.findDevicePoliciesByDevice(Unknown Source)
                           at net.lgsystems.policy.mgr.PolicyMgrImpl.addDevicePolicy(PolicyMgrImpl.java:389)
                           at net.lgsystems.policy.ejb.PolicyManagementBean.addDevicePolicyForGroup(PolicyManagementBean.java:277)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
                           at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:168)
                           at net.lgsystems.access.core.AccessInterceptor.process(AccessInterceptor.java:80)
                           at sun.reflect.GeneratedMethodAccessor439.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:120)
                           at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:62)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
                           ... 58 more
                          Caused by: org.jboss.serial.exception.SerializationException
                           at org.jboss.serial.persister.PrivateWritePersister.writeData(PrivateWritePersister.java:83)
                           at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
                           at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:260)
                           at org.jboss.serial.io.JBossObjectOutputStream.writeObjectOverride(JBossObjectOutputStream.java:111)
                           at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:287)
                           at org.jboss.serial.io.MarshalledObject.<init>(MarshalledObject.java:51)
                           at org.jboss.ejb3.SessionContainer.marshallResponse(SessionContainer.java:211)
                           at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:223)
                           at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:55)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
                           ... 77 more
                          Caused by: java.lang.reflect.InvocationTargetException
                           at sun.reflect.GeneratedMethodAccessor200.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.serial.persister.PrivateWritePersister.writeData(PrivateWritePersister.java:73)
                           ... 87 more
                          Caused by: java.lang.ClassCastException: [Ljava.lang.Class;
                           at org.jboss.serial.persister.ClassReferencePersister.writeData(ClassReferencePersister.java:42)
                           at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
                           at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:260)
                           at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:81)
                           at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:46)
                           at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
                           at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:260)
                           at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:81)
                           at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:46)
                           at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
                           at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:260)
                           at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:81)
                           at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:46)
                           at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
                           at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:260)
                           at org.jboss.serial.persister.ObjectOutputStreamProxy.writeObjectOverride(ObjectOutputStreamProxy.java:45)
                           at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:287)
                           at java.util.ArrayList.writeObject(ArrayList.java:570)
                           ... 91 more


                          • 40. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                            ejb3workshop

                            Could you please post you beam implementation.

                            • 41. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                              jwynett

                              I believe the last post refers to me. Here is the root entity bean that is having the various problems. Every other bean that has a relationship to it seems to inherit its problems.

                              @Entity
                              @Table(name = "device")
                              public class Device extends EntityBase implements SecureEntity {
                               private long id;
                               private String displayName;
                               private boolean isManageable;
                               private Set<DeviceInterface> interfaces = new HashSet<DeviceInterface>();
                               private long organizationId;
                               private String hostName;
                               private Date createDate;
                               private ManagedAsset asset;
                               private Device deviceRef;
                               private boolean isInactive;
                               private Date policyRefreshDate;
                               private PolicyGroup policyGroup;
                               private Set<DevicePolicy> devicePolicies = new HashSet<DevicePolicy>();
                              
                               public Device() {
                               /* default constructor */
                               }
                              
                               public Device(String displayName, boolean isManageable, long organizationId) throws LocalizableException {
                               this.displayName = displayName;
                               this.isManageable = isManageable;
                               this.organizationId = organizationId;
                               validate();
                               }
                              
                               /**
                               * Primary Key
                               */
                               @Id @GeneratedValue
                               @Column(name = "device_id")
                               public long getId() {
                               return id;
                               }
                              
                               public void setId(long id) {
                               this.id = id;
                               }
                              
                               /**
                               * The host name of the asset
                               *
                               * @return String
                               */
                               @Column(name = "host_name", nullable = true, length = 64)
                               public String getHostName() {
                               return hostName;
                               }
                              
                               public void setHostName(String hostName) {
                               this.hostName = hostName;
                               }
                              
                               /**
                               * Indicates whether this device is manageable. At the current time only
                               * Windows boxes are manageable and all else is unmanageable. To find
                               * out if a manageable device is managed, check whether getAsset() is
                               * equal to null or not.
                               *
                               * @return boolean
                               */
                               @Column(name = "is_manageable", nullable = false)
                               public boolean isManageable() {
                               return isManageable;
                               }
                              
                               public void setManageable(boolean manageable) {
                               isManageable = manageable;
                               }
                              
                               /**
                               * Display name of the device.
                               *
                               * @return String
                               */
                               @Column(name = "display_name", length = 64, nullable = false)
                               public String getDisplayName() {
                               return displayName;
                               }
                              
                               public void setDisplayName(String displayName) {
                               this.displayName = displayName;
                               }
                              
                               /**
                               * Date/Time this asset was created.
                               *
                               * @return Date
                               */
                               @Column(name = "create_date", nullable = false)
                               public Date getCreateDate() {
                               return createDate;
                               }
                              
                               public void setCreateDate(Date createDate) {
                               if (this.createDate == null) {
                               this.createDate = createDate;
                               }
                               }
                              
                               /**
                               * Indicates the time when the device last received current policies. This is
                               * set when the device replies with confirmation that new policies have been
                               * received. It is used to determine if device is up-to-date with policies.
                               *
                               * @return Date
                               */
                               @Column(name = "policy_refresh_date", nullable = true)
                               public Date getPolicyRefreshDate() {
                               return policyRefreshDate;
                               }
                              
                               public void setPolicyRefreshDate(Date policyRefreshDate) {
                               this.policyRefreshDate = policyRefreshDate;
                               }
                              
                               /**
                               * Get the organization id associated with the entity. Supports security
                               * checks based on organization relationships. (For SecureEntity)
                               *
                               * @return long
                               */
                               @Column(name = "organization_ref_id", nullable = false)
                               public long getOrganizationId() {
                               return organizationId;
                               }
                              
                               public void setOrganizationId(long organizationId) {
                               this.organizationId = organizationId;
                               }
                              
                               /**
                               * The set of network interfaces for this device.
                               *
                               * @return Set<DeviceInterface>
                               */
                               @OneToMany(fetch = FetchType.LAZY, mappedBy = "device")
                               public Set<DeviceInterface> getInterfaces() {
                               return interfaces;
                               }
                              
                               public void setInterfaces(Set<DeviceInterface> interfaces) {
                               this.interfaces = interfaces;
                               }
                              
                               /**
                               * Returns the interface that matches the given mac address. If a
                               * match is not found, method returns null.
                               *
                               * @param macAddress
                               * @return DeviceInterface or null
                               */
                               @Transient
                               public DeviceInterface getInterfaceForMacAddress(String macAddress) {
                               for (DeviceInterface devInt : getInterfaces()) {
                               if (devInt.getMacAddress().equals(macAddress)) {
                               return devInt;
                               }
                               }
                               return null;
                               }
                              
                               /**
                               * The asset association if this device is managed. Can be null
                               * for unmanaged devices.
                               *
                               * @return ManagedAsset
                               */
                               /* TODO:JWW:FETCH Should be LAZY. EnhancedCGLib proxy problems. */
                               @OneToOne(fetch = FetchType.EAGER, optional = true)
                               @JoinColumn(name = "asset_id", nullable = true, updatable = true)
                               public ManagedAsset getAsset() {
                               return asset;
                               }
                              
                               public void setAsset(ManagedAsset asset) {
                               this.asset = asset;
                               }
                              
                               /**
                               * This points to a reference device that is created when this device is deactivated. This
                               * can happen during an enrollment when multiple devices are consolidated into a single
                               * new device. Normally, when this field is set, the inactive field should also be true.
                               * The end result is we can keep devices around for historical purposes leaving them
                               * inactive and pointing to a successor device.
                               *
                               * @return Device
                               */
                               /* TODO:JWW:FETCH Should be LAZY. EnhancedCGLib proxy problems. */
                               @ManyToOne(fetch = FetchType.EAGER)
                               @JoinColumn(name = "ref_device_id", nullable = true, updatable = true)
                               public Device getDeviceReference() {
                               return deviceRef;
                               }
                              
                               public void setDeviceReference(Device deviceRef) {
                               this.deviceRef = deviceRef;
                               }
                              
                               /**
                               * The PolicyGroup to which this Device belongs to.
                               *
                               * @return PolicyGroup
                               */
                               /* TODO:JWW:FETCH Should be LAZY. EnhancedCGLib proxy problems. */
                               @ManyToOne(fetch = FetchType.EAGER, optional = true)
                               @JoinColumn(nullable = true, name = "policy_group_id")
                               public PolicyGroup getPolicyGroup() {
                               return policyGroup;
                               }
                              
                               public void setPolicyGroup(PolicyGroup policyGroup) {
                               this.policyGroup = policyGroup;
                               }
                              
                               /**
                               * The set of policies assigned to this Device. These include policies assigned
                               * via a PolicyGroup plus manual overrides.
                               *
                               * @return Set<Policy>
                               */
                               @OneToMany(fetch = FetchType.LAZY, mappedBy = "device")
                               public Set<DevicePolicy> getDevicePolicies() {
                               return devicePolicies;
                               }
                              
                               public void setDevicePolicies(Set<DevicePolicy> devicePolicies) {
                               this.devicePolicies = devicePolicies;
                               }
                              
                               /**
                               * Indicates whether this device is considered inactive. A device becomes inactive when a
                               * new device is created to take its place and it is kept around for historical purposes.
                               * See the getDeviceReference() method for more information.
                               *
                               * @return boolean
                               */
                               @Column(name = "is_inactive", nullable = false)
                               public boolean isInactive() {
                               return isInactive;
                               }
                              
                               public void setInactive(boolean inactive) {
                               isInactive = inactive;
                               }
                              
                               /**
                               * Version field used for optimistic locking control. This is automatically
                               * handled by the system and you do not have to manually update this field.
                               * The @Version annotation triggers hibernate to use this field for versioning.
                               *
                               * @return Integer
                               */
                               @Version
                               @Column(name = "lock_version", nullable = false)
                               public Integer getLockVersion() {
                               return super.lockVersion;
                               }
                              
                               public void setLockVersion(Integer version) {
                               lockVersion = version;
                               }
                              
                              
                               /**
                               * Get an identifier for this entity. (For SecureEntity)
                               *
                               * @return Object
                               */
                               @Transient
                               public Object getEntityId() {
                               return getId();
                               }
                              
                               /**
                               * Check equality of this entity with another object.
                               *
                               * @param o entity to compare
                               * @return boolean
                               */
                               public boolean equals(final Object o) {
                               if (this == o) {
                               return true;
                               }
                               if (o == null || !(o instanceof Device)) {
                               return false;
                               }
                               Device that = (Device) o;
                               return (this.getId() == that.getId());
                               }
                              
                               /**
                               * Get the hash code of this entity. Usually mapped to the primary key.
                               *
                               * @return int
                               */
                               public int hashCode() {
                               return (int) this.getId();
                               }
                              
                               /**
                               * Get String representation of this entity.
                               *
                               * @return String
                               */
                               public String toString() {
                               return new StringBuilder().append("Device(").append(this.getId()).append("/").append(getDisplayName()).append(")").toString();
                               }
                              
                               public void validate() throws LocalizableException {
                               if (displayName == null) {
                               throw new LocalizableException(ServerErrors.ERROR_FIELD_MISSING_F1, "Display Name");
                               }
                               if (organizationId < 1) {
                               throw new LocalizableException(ServerErrors.ERROR_FIELD_MISSING_F1, "Organization Id");
                               }
                               if (isManageable == false && getAsset() != null) {
                               throw new LocalizableException(ServerErrors.ERROR_VALIDATION_F1, "Device cannot be 'unmanageable' and have an asset relationship");
                               }
                               }
                              


                              • 42. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                                ejb3workshop

                                I was hoping for the implementation of the findDevicePoliciesByDevice method. In particular the remote interface would also be good to take a look at.


                                Caused by: java.lang.reflect.UndeclaredThrowableException
                                at $Proxy273.findDevicePoliciesByDevice(Unknown Source)
                                at net.lgsystems.policy.mgr.PolicyMgrImpl.addDevicePolicy(PolicyMgrImpl.java:389)
                                at net.lgsystems.policy.ejb.PolicyManagementBean.addDevicePolicyForGroup(PolicyManagementBean.java:
                                277)


                                Thanks
                                Alex

                                • 43. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                                  jwynett

                                  Below is the method. The actual query will resolve to:

                                  "FROM DevicePolicy devicePolicy WHERE devicePolicy.device = :device"

                                   public Collection<DevicePolicy> findDevicePoliciesByDevice(Device device, boolean includeDeleted, EagerOnDemand onDemand) throws LocalizableException {
                                   String alias = DevicePolicy.ROOT.getAlias();
                                   String from = Helper.getEagerFromClause(DevicePolicy.ROOT, onDemand);
                                   String deletedClause = includeDeleted ? "" : " AND " + alias + ".deleted = false ";
                                   try {
                                   Collection<DevicePolicy> list = (Collection<DevicePolicy>) entityMgr.createQuery(from +
                                   " WHERE " + alias + ".device = :device" + deletedClause)
                                   .setParameter("device", device)
                                   .getResultList();
                                   EagerOnDemand.loadRelationships(list, onDemand);
                                   return list;
                                   }
                                   catch (Exception e) {
                                   logger.error("Unexpected Error", e);
                                   throw new LocalizableException(ServerErrors.ERROR_UNEXPECTED_F1, e, e.getMessage());
                                   }
                                   }
                                  


                                  The PolicyFinder superinterface and PolicyFinderRemote interface that expose this method are below:
                                  /*
                                   * Copyright (c) 2005 Looking Glass Systems, Inc. All Rights Reserved.
                                   */
                                  package net.lgsystems.policy.ejb;
                                  
                                  import javax.ejb.Remote;
                                  
                                  /**
                                   * <p/>
                                   *
                                   * @author Jon Wynett
                                   * Created: Nov 17, 2005 10:19:20 AM
                                   */
                                  @Remote
                                  public interface PolicyFinderRemote extends PolicyFinder {
                                  }
                                  

                                  /*
                                   * Copyright (c) 2005 Looking Glass Systems, Inc. All Rights Reserved.
                                   */
                                  package net.lgsystems.policy.ejb;
                                  
                                  import net.lgsystems.network.entity.Device;
                                  import net.lgsystems.policy.entity.DevicePolicy;
                                  import net.lgsystems.policy.entity.Policy;
                                  import net.lgsystems.policy.entity.PolicyGroup;
                                  import net.lgsystems.policy.util.PolicyType;
                                  import net.lgsystems.util.EagerOnDemand;
                                  import net.lgsystems.util.LocalizableException;
                                  
                                  import java.util.Collection;
                                  
                                  /**
                                   * <p/>
                                   *
                                   * @author Jon Wynett
                                   * Created: Nov 17, 2005 10:18:37 AM
                                   */
                                  public interface PolicyFinder {
                                  
                                   /**
                                   * Find a policy entity by its primary key.
                                   *
                                   * @param policyId
                                   * @param onDemand
                                   * @return Policy
                                   * @throws LocalizableException
                                   */
                                   public Policy findPolicyById(long policyId, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Find a policy entity by its display name. This is a unique field
                                   *
                                   * @param displayName
                                   * @param onDemand
                                   * @return Policy
                                   * @throws LocalizableException
                                   */
                                   public Policy findPolicyByName(String displayName, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Find a collection of policies by the PolicyType.
                                   *
                                   * @param policyType
                                   * @param onDemand
                                   * @return Policy
                                   * @throws LocalizableException
                                   */
                                   public Collection<Policy> findPoliciesByType(PolicyType policyType, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Get all the policies assigned to a given device. This list can be filtered. If not filtered, every single re
                                   * @param deviceId
                                   * @param filtered
                                   * @param onDemand
                                   * @return
                                   * @throws LocalizableException
                                   */
                                   //public Collection<Policy> getPoliciesForDevice(long deviceId, boolean filtered, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Retrieve all policy entities.
                                   *
                                   * @param onDemand
                                   * @return Collection<Policy>
                                   */
                                   public Collection<Policy> getPolicies(EagerOnDemand onDemand);
                                  
                                   /**
                                   * Find a policy group entity by its primary key.
                                   *
                                   * @param policyGroupId
                                   * @param onDemand
                                   * @return PolicyGroup
                                   * @throws LocalizableException
                                   */
                                   public PolicyGroup findPolicyGroupById(long policyGroupId, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Find a policyGroup entity by its group name. This is a unique field
                                   *
                                   * @param groupName
                                   * @param onDemand
                                   * @return PolicyGroup
                                   * @throws LocalizableException
                                   */
                                   public PolicyGroup findPolicyGroupByName(String groupName, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Retrieve all policyGroup entities.
                                   *
                                   * @param onDemand
                                   * @return Collection<PolicyGroup>
                                   */
                                   public Collection<PolicyGroup> getPolicyGroups(EagerOnDemand onDemand);
                                  
                                   /**
                                   * Find devicePolicy entities for a given policy.
                                   *
                                   * @param policy
                                   * @param onDemand
                                   * @return Collection<DevicePolicy>
                                   * @throws net.lgsystems.util.LocalizableException
                                   *
                                   */
                                   public Collection<DevicePolicy> findDevicePoliciesByPolicy(Policy policy) throws LocalizableException;
                                  
                                   /**
                                   * Find a devicePolicy entity by its primary key.
                                   *
                                   * @param devicePolicyId
                                   * @param onDemand
                                   * @return DevicePolicy
                                   * @throws LocalizableException
                                   */
                                   public DevicePolicy findDevicePolicyById(long devicePolicyId, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Get all devicePolicy entities.
                                   *
                                   * @param onDemand
                                   * @return Collection<DevicePolicy>
                                   */
                                   public Collection<DevicePolicy> getDevicePolicies(EagerOnDemand onDemand);
                                  
                                   /**
                                   * Finds a DevicePolicy entity by its unique key, device and policy.
                                   *
                                   * @param device
                                   * @param policy
                                   * @param includeDeleted true to include all records. false to exclude those marked for deletion
                                   * @param onDemand
                                   * @return DevicePolicy
                                   * @throws LocalizableException
                                   */
                                   public DevicePolicy findDevicePolicyByDeviceAndPolicy(Device device, Policy policy, boolean includeDeleted, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Finds a list of DevicePolicy entities by device.
                                   *
                                   * @param device
                                   * @param includeDeleted true to include all records. false to exclude those marked for deletion
                                   * @param onDemand
                                   * @return Collection<DevicePolicy>
                                   */
                                   public Collection<DevicePolicy> findDevicePoliciesByDevice(Device device, boolean includeDeleted, EagerOnDemand onDemand) throws LocalizableException;
                                  
                                   /**
                                   * Returns all the Policies for a given device filtered by override status returning only
                                   * the policies that should be active.
                                   *
                                   * @param device
                                   * @return Collection<Policy>
                                   * @throws LocalizableException
                                   */
                                   public Collection<Policy> findFilteredPoliciesForDevice(Device device) throws LocalizableException;
                                  }


                                  • 44. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                                    ejb3workshop

                                    Could you please have a look if an exception occurs on the server side. I would expect a entry in the log by :

                                    logger.error("Unexpected Error", e);


                                    Thanks
                                    Alex