Hi again
Im still getting the same kind of error, here is some more code (maybe it's
not related to recursion?)
My nodes are created using:
tm.addNode("test1", "test1");
tm.addNode("test2", "test2", tm.getNodeIdFromPath("test1"));
tm.addNode("test3", "test3", tm.getNodeIdFromPath("test1.test2"));
tm.addNode("test4", "test4",
tm.getNodeIdFromPath("test1.test2.test3"));
And tm.addNode is:
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public long addNode(String name, String displayName, long parentId) {
Node node = new Node();
node.setName(name.toLowerCase());
node.setDisplayName(displayName);
node.setParent( getNode(parentId) );
em.persist(node);
em.flush();
return node.getId();
}
tm.getNodeIdFromPath works fine (it fetches the correct id).
Node.parent is now defined as:
@ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
@JoinColumn(name="parent")
protected Node parent;
The problem here is, adding the three first nodes works correct, but test4
does not (tm.getNodeIdFromPath works on test1.test2.test3).
A snippet from the error log:
DEBUG - [openjpa.jdbc.SQL] <t 12777822, conn 0> executing prepstmnt 15317735
SELECT t1.id, t1.nodeType, t1.displayName, t1.name, t1.courseCode,
t1.endDate, t1.startDate FROM NODE t0 INNER JOIN NODE t1 ON t0.parent =
t1.id WHERE t0.id = ? [params=(long) 23]
DEBUG - [openjpa.jdbc.SQL] <t 12777822, conn 0> [0 ms] spent
DEBUG - [openjpa.jdbc.JDBC] <t 12777822, conn 0> [0 ms] close
DEBUG - [OpenEJB] The bean instance business method encountered a system
exception: null
<openjpa-1.1.0-r422266:659716 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: null
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2459)
at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2277)
at
org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1021)
at
org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:645)
at
org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:97)
This error does not occur when i try to only create 3 nodes. I thought this
was because of recursion depth, but now i'm thinking its not (the log
confirms that depth is -1).
Do I need to update my parent node when the get pointed to by a child?
I use openejb if that makes a differense (openjpa 1.1.0), and also use
inheritance (but that part seems to work fine). I have also added the
openjpa enhancer (the maven plugin had already enabled runtime enhancing).
Any tips would be greatly appreciated.
//Morten
On Fri, May 15, 2009 at 15:34, Morten O. Hansen <mortenoh@gmail.com> wrote:
> Ok, thank you. Hopefully i can get it to work :)
>
> //Morten
>
>
> On Fri, May 15, 2009 at 15:32, <Naomi-san@gmx.de> wrote:
>
>> Hi,
>>
>> best, you have a look at the documentation:
>>
>>
>><>
>>
>> OpenJPA classes need to be enhanced to provide lazy fetching. Else there
>> will always been used eager fetching, which could be the cause of your
>> problem.
>>
>> -------- Original-Nachricht --------
>> > Datum: Fri, 15 May 2009 15:26:43 +0200
>> > Von: "Morten O. Hansen" <mortenoh@gmail.com>
>> > An: users@openjpa.apache.org
>> > Betreff: Re: Creating nodes with parents
>>
>> > Hi
>> >
>> > Thank for your quick response :) Sorry for my ignorance, but what do you
>> > mean by enhancing the classes?
>> >
>> > //Morten
>> >
>> > On Fri, May 15, 2009 at 15:21, <Naomi-san@gmx.de> wrote:
>> >
>> > > Hi,
>> > >
>> > > as far as I know, TopLink has a maximum fetching depth of 2 by default
>> > and
>> > > OpenJPA has an infinite fetching depth, which could lead to recursions
>> > in
>> > > the worst case if you use eager fetching.
>> > > I am wondering why this also happens with lazy fetching - did you
>> forget
>> > to
>> > > enhance your classes?
>> > >
>> > > You can set the maximum fetching depth in your persistence.xml by
>> > setting
>> > > the following property:
>> > >
>> > > <property name="openjpa.MaxFetchDepth" value="2"/>
>> > >
>> > > I hope this helps :)
>> > >
>> > > -------- Original-Nachricht --------
>> > > > Datum: Fri, 15 May 2009 14:58:03 +0200
>> > > > Von: "Morten O. Hansen" <mortenoh@gmail.com>
>> > > > An: users@openjpa.apache.org
>> > > > Betreff: Creating nodes with parents
>> > >
>> > > > Hi all
>> > > >
>> > > > I'm trying to create a Node class, where every Node has a pointer
to
>> a
>> > > > parent Node (or null if there is none).
>> > > >
>> > > > A simplified view of the Node-class looks like this:
>> > > >
>> > > > @Entity
>> > > > public class Node {
>> > > > @Id protected long id;
>> > > > @ManyToOne(fetch=LAZY)
>> > > > protected Node parent;
>> > > > protected String name;
>> > > > protected String displayName;
>> > > >
>> > > > // setters / getters..
>> > > > }
>> > > >
>> > > > And this was working correctly in TopLink (I think they just do
>> > infinite
>> > > > recursion depth), but in OpenJPA i get something that looks like
>> > > recursion
>> > > > errors.
>> > > >
>> > > > Is there a better way of doing this? I have implemented a hack just
>> > using
>> > > > long parentId instead, but that kinda sucks when you are deleting
>> and
>> > > > updating nodes.
>> > > >
>> > > > I know there is something called FetchGroups in OpenJPA, but i
>> > couldn't
>> > > > really get them to work and I want to have entities that hopefully
>> > isn't
>> > > > tied down to OpenJPA.
>> > > >
>> > > > --
>> > > > Morten
>> > >
>> > > --
>> > > Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate +
>> > > Telefonanschluss für nur 17,95 Euro/mtl.!*
>> > >
>> > >
>>
>> --
>> Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate +
>> Telefonanschluss für nur 17,95 Euro/mtl.!*
>>
>>
>
>