Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] select part of an entity

I solved the problem by creating a new function that query's for the htmlbody

    public String getHtmlbody(Email email)
    {
return (String) em.createQuery("select e.htmlbody from Email e where e = :email")
                .setParameter("email", email)
                .getSingleResult();
    }


If there is a better solution, please let me know!!   :)


Derek


On 03/03/10 13:34, Derek Knapp wrote:
Is there a way I can manually tell it to fetch the column in the queries that need it?

Derek

On 03/02/10 18:44, Derek Knapp wrote:
I now get this exception when loading an email that accesses this field

Long emailid = Long.parseLong(request.getParameter("emailid"));
            Email email = emailFacade.find(emailid);
            html = email.getHtmlbody();


My understanding was that this would automatically be loaded from the database when/if needed

Any pointers would be greatly appreciated!!


Derek



StandardWrapperValve[viewemail]: PWC1406: Servlet.service() for servlet viewemail threw exception
Local Exception Stack:
Exception [EclipseLink-6004] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.QueryException Exception Description: The object [com.iTrac.Entity.Email[emailid=21444]], of class [class com.iTrac.Entity.Email], with identity hashcode (System.identityHashCode()) [15,615,811], is not from this UnitOfWork object space, but the parent session's. The object was never registered in this UnitOfWork, but read from the parent session and related to an object registered in the UnitOfWork. Ensure that you are correctly registering your objects. If you are still having problems, you can use the UnitOfWork.validateObjectSpace() method to help debug where the error occurred. For more information, see the manual or FAQ.
Query: ReadObjectQuery(com.iTrac.Entity.Email)
at org.eclipse.persistence.exceptions.QueryException.backupCloneIsOriginalFromParent(QueryException.java:237) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.getBackupClone(UnitOfWorkImpl.java:1752) at org.eclipse.persistence.descriptors.FetchGroupManager.writePartialIntoClones(FetchGroupManager.java:173) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerExistingObject(UnitOfWorkImpl.java:3579) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerExistingObject(UnitOfWorkImpl.java:3523) at org.eclipse.persistence.queries.ObjectBuildingQuery.registerIndividualResult(ObjectBuildingQuery.java:363) at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneNormally(ObjectBuilder.java:555) at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:517) at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:461) at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:413) at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:521) at org.eclipse.persistence.queries.ReadObjectQuery.registerResultInUnitOfWork(ReadObjectQuery.java:707) at org.eclipse.persistence.queries.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:431) at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:879) at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:666) at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:840) at org.eclipse.persistence.queries.ReadObjectQuery.execute(ReadObjectQuery.java:398) at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:902) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2587) at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1178) at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1162) at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1108) at org.eclipse.persistence.jpa.JpaHelper.loadUnfetchedObject(JpaHelper.java:200)
        at com.iTrac.Entity.Email._persistence_checkFetched(Email.java)
        at com.iTrac.Entity.Email._persistence_gethtmlbody(Email.java)
        at com.iTrac.Entity.Email.getHtmlbody(Email.java:287)
        at itrac.report.view.processRequest(view.java:41)
        at itrac.report.view.doGet(view.java:75)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

On 02/25/10 14:18, Derek Knapp wrote:
thank you so much Tom!! that did exactly what I wanted.

I knew it was possible for join's, but didn't know I could do it on a normal column!!


Derek

On 02/25/10 13:50, Tom Ware wrote:
Hi Derek,

Try simply specifying the LAZY fetch type on the annotation for your mapping or in the orm.xml.

e.g.

    @Basic(fetch=FetchType.LAZY)

-Tom



Derek Knapp wrote:
I have a table, which I run a very simple select on, for example,

    select e from Email e where e.createDate between :start and :end

but the problem is that the Email has a column "body" which contains a lot of data, and I really don't need that information right now.... is there a way to make it not select that column?

the only solution I can think of is to create a new class with the fields I want from the Email entity, then do something like

select new itrac.data.EmailReport(e.id, e.name, e.subject, ...) from Email e where e.createDate between :start and :end

but is there a better way??


Derek
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top