|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Re: Mapping QuestionHello,
Collection mappings (OneToMany and ManyToMany) are lazy loaded by default, so adding the FetchType.LAZY to them won't change anything unless they were explicitly eager before. The fact that it is terminating without an error is troubling, as Java should throw or log an exception somewhere. I doubt though that it is connections - any number of reads for a single tree will use the same connection, so it could be an OutOfMemory or other JVM error. Other than increasing the memory and the heap, you can make some of the backward relationships also lazy - specifically the ManyToOne back pointers. This will prevent the entire tree from being inadvertently brought into memory when not needed. You can also look at where a relationship is not strictly needed and unmap them - bringing them in using a query instead when they are needed. For instance, in a ManyToMany, it may not be necessary to have both sides mapped if the application will only ever us it from one side. Best Regards, Chris Roger wrote: > Hi > > I have a series of entities representing a hierarchy. Entity1 has many Entity2 > which in turn has many Entity3 which in turn ... etc, etc. > > Entity1 maps Entity2 with a @OneToMany and Entity2 maps to Entity1 with > @ManyToOne and Fetch=FetchType.Lazy. This is repeated down the heirarchy. > > So far, this has been working well since I'm usually starting at the top of > the hierarchy until this afternoon when I was lumbered with one of those > urgent, need it yesterday type of jobs. What I needed to do was to read > through the entities that live at the bottom level of the hierarchy. For each > entity, EclipseLink walked up the hierarchy (running with debug level > logging) and terminated midway through the query with > no obvious error messages, so whether it ran out of DB Connections or memory I > don't know. I tried adding fetch = FetchType.LAZY to the @OneToMany mappings > with no effect. > > Is there anything I can do to stop EclipseLInk doing this and only walking > back up the hierarchy when I try to access the level above. In this particular > instance all the data I need is in the bottom level entity, > > Regards > > > _______________________________________________ > eclipselink-users mailing list > eclipselink-users@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users > eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Mapping QuestionHi
I have a series of entities representing a hierarchy. Entity1 has many Entity2 which in turn has many Entity3 which in turn ... etc, etc. Entity1 maps Entity2 with a @OneToMany and Entity2 maps to Entity1 with @ManyToOne and Fetch=FetchType.Lazy. This is repeated down the heirarchy. So far, this has been working well since I'm usually starting at the top of the hierarchy until this afternoon when I was lumbered with one of those urgent, need it yesterday type of jobs. What I needed to do was to read through the entities that live at the bottom level of the hierarchy. For each entity, EclipseLink walked up the hierarchy (running with debug level logging) and terminated midway through the query with no obvious error messages, so whether it ran out of DB Connections or memory I don't know. I tried adding fetch = FetchType.LAZY to the @OneToMany mappings with no effect. Is there anything I can do to stop EclipseLInk doing this and only walking back up the hierarchy when I try to access the level above. In this particular instance all the data I need is in the bottom level entity, Regards _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionHi Roger,
Is there a relationship between a child and its parent? Most of the time, a parent will have a OneToMany with a child, and the child will have a ManyToOne relationship back. Mark the @ManyToOne relationship as lazy - as well as all other relationships that you might not want to always load. Best Regards, Chris Roger wrote: > On Thursday 24 September 2009 19:57:58 christopher delahunt wrote: > > >> Other than increasing the memory and the heap, you can make some of the >> backward relationships also lazy - specifically the ManyToOne back >> pointers. This will prevent the entire tree from being inadvertently >> brought into memory when not needed. >> > > Is there a different annotation needed on the @OneToMany backpointer as I have > already tried that. and EclipseLInk still walked back up the tree. > > >> You can also look at where a >> relationship is not strictly needed and unmap them - bringing them in >> using a query instead when they are needed. For instance, in a >> ManyToMany, it may not be necessary to have both sides mapped if the >> application will only ever us it from one side. >> >> > > That looks like the quickest solution. I will try that in the morning > temporarily to get my job done, but I would like to get to the bottom of > what's going on and to be able to have some degree of control over back- > walking - if it's possible. > > Regards > _______________________________________________ > eclipselink-users mailing list > eclipselink-users@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users > eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionOn Thursday 24 September 2009 19:57:58 christopher delahunt wrote:
> > Other than increasing the memory and the heap, you can make some of the > backward relationships also lazy - specifically the ManyToOne back > pointers. This will prevent the entire tree from being inadvertently > brought into memory when not needed. Is there a different annotation needed on the @OneToMany backpointer as I have already tried that. and EclipseLInk still walked back up the tree. > You can also look at where a > relationship is not strictly needed and unmap them - bringing them in > using a query instead when they are needed. For instance, in a > ManyToMany, it may not be necessary to have both sides mapped if the > application will only ever us it from one side. > That looks like the quickest solution. I will try that in the morning temporarily to get my job done, but I would like to get to the bottom of what's going on and to be able to have some degree of control over back- walking - if it's possible. Regards _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionSorry, I understand the problem now. Though you have Lazy turned on, it
can only work on OneToOne and ManyToOne if you are using weaving. Lazy loading on OneToMany and ManyToMany doesn't require weaving since they can use a collection implementation, which is why they are lazy by default and the others have to be set. Weaving can be done statically or at runtime through a java agent as described: http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving Best Regards, Chris Roger wrote: > On Thursday 24 September 2009 20:51:07 christopher delahunt wrote: > >> Hi Roger, >> >> Is there a relationship between a child and its parent? Most of the >> time, a parent will have a OneToMany with a child, and the child will >> have a ManyToOne relationship back. Mark the @ManyToOne relationship as >> lazy - as well as all other relationships that you might not want to >> always load. >> >> > > Hi Chris > > The parent is mapped OneToMany with the child and the child is mapped > ManyToOne with t he parent. The child ManyToOne relationship is also mapped as > LAZY. This works fine when I'm processing the Parent, access to the Child > happens only when requested. However, if I start processing at the Child (i.e > I don't retrieve the parent to get a list of the children and process each > child i.e I want to process all Children of all Parents and I don't require > any of the data held at the Parent level, EclipseLink is generating an > additional query to retrieve the Parent. I've tried making the OneToMany link > in the parent lazy as well, but it doesn't seem to have any effect. > > I hope that the above actually makes sense to everyone. > > Regards > _______________________________________________ > eclipselink-users mailing list > eclipselink-users@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users > eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionOn Thursday 24 September 2009 20:51:07 christopher delahunt wrote:
> Hi Roger, > > Is there a relationship between a child and its parent? Most of the > time, a parent will have a OneToMany with a child, and the child will > have a ManyToOne relationship back. Mark the @ManyToOne relationship as > lazy - as well as all other relationships that you might not want to > always load. > Hi Chris The parent is mapped OneToMany with the child and the child is mapped ManyToOne with t he parent. The child ManyToOne relationship is also mapped as LAZY. This works fine when I'm processing the Parent, access to the Child happens only when requested. However, if I start processing at the Child (i.e I don't retrieve the parent to get a list of the children and process each child i.e I want to process all Children of all Parents and I don't require any of the data held at the Parent level, EclipseLink is generating an additional query to retrieve the Parent. I've tried making the OneToMany link in the parent lazy as well, but it doesn't seem to have any effect. I hope that the above actually makes sense to everyone. Regards _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionAhh - this answers a question that I've been meaning to ask. I didn't
know why (or how) my entities were being lazy loaded when I wasn't weaving or using the agent. Is this documented somewhere? thanks, Mike christopher delahunt wrote: > Sorry, I understand the problem now. Though you have Lazy turned on, > it can only work on OneToOne and ManyToOne if you are using weaving. > Lazy loading on OneToMany and ManyToMany doesn't require weaving since > they can use a collection implementation, which is why they are lazy > by default and the others have to be set. Weaving can be done > statically or at runtime through a java agent as described: > > http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving > > > Best Regards, > Chris > > Roger wrote: >> On Thursday 24 September 2009 20:51:07 christopher delahunt wrote: >> >>> Hi Roger, >>> >>> Is there a relationship between a child and its parent? Most of the >>> time, a parent will have a OneToMany with a child, and the child will >>> have a ManyToOne relationship back. Mark the @ManyToOne >>> relationship as >>> lazy - as well as all other relationships that you might not want to >>> always load. >>> >>> >> >> Hi Chris >> >> The parent is mapped OneToMany with the child and the child is mapped >> ManyToOne with t he parent. The child ManyToOne relationship is also >> mapped as LAZY. This works fine when I'm processing the Parent, >> access to the Child happens only when requested. However, if I start >> processing at the Child (i.e I don't retrieve the parent to get a >> list of the children and process each child i.e I want to process >> all Children of all Parents and I don't require any of the data held >> at the Parent level, EclipseLink is generating an additional query to >> retrieve the Parent. I've tried making the OneToMany link in the >> parent lazy as well, but it doesn't seem to have any effect. >> >> I hope that the above actually makes sense to everyone. >> >> Regards >> _______________________________________________ >> eclipselink-users mailing list >> eclipselink-users@... >> https://dev.eclipse.org/mailman/listinfo/eclipselink-users >> > _______________________________________________ > eclipselink-users mailing list > eclipselink-users@... > https://dev.eclipse.org/mailman/listinfo/eclipselink-users eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionOn Thursday 24 September 2009 22:16:38 christopher delahunt wrote:
> Sorry, I understand the problem now. Though you have Lazy turned on, it > can only work on OneToOne and ManyToOne if you are using weaving. Lazy > loading on OneToMany and ManyToMany doesn't require weaving since they > can use a collection implementation, which is why they are lazy by > default and the others have to be set. Weaving can be done statically > or at runtime through a java agent as described: > > http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_Eclip >seLink_JPA_Weaving > looking for clues as to why the query appears to simply terminate. I'm running the program within Galileo. Regards Roger _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: Mapping QuestionEmbarrasingly - the query doesn't terminate. It was my code following that terminated the app just after the query returned. I guess I was so fixated on why EclipseLink was back-walking the hierarchy that I jumped to an incorrect conclusion. Sorry |
| Free embeddable forum powered by Nabble | Forum Help |