Problem with Traversing

11 views
Skip to first unread message

Stefan Berndt

unread,
Jun 24, 2010, 5:30:05 AM6/24/10
to jo4neo
Hey,

I was trying to add traverse functionality to my little demo app, but
i get a ClassCastException in my Testcases by doing
ObjectGraph.get(Module.class)

My datamodel looks like this:

Module.class:

@InjectWith(InjectorProviderA.class)
public class Module {
// ------------------------------ FIELDS
------------------------------

@Inject
Injector injector;
@Inject
DatabaseService ds;
transient Nodeid node;
@neo("HAS_BASIC_ITEM")
Collection<BasicItem> basicItems = new ArrayList<BasicItem>();
@neo("HAS_MODULE")
Collection<Module> modules = new ArrayList<Module>();
@neo(index=true)
private String name;
@neo(traverser=ModuleTraverser.class)
private Collection elements;

....

}

BasicItem.class:

@InjectWith(InjectorProviderA.class)
public class BasicItem {
// ------------------------------ FIELDS
------------------------------

@Inject
Injector injector;
@Inject
DatabaseService ds;
transient Nodeid node;
@neo(index=true)
private String name;

...

}

RelationShips.class:

public enum RelationShips implements RelationshipType
{
HAS_MODULE,
HAS_BASIC_ITEM,
HAS_BASIC_TEMPLATE,
HAS_CONCRETE_TEMPLATE,
HAS_SYSTEM

}

ModuleTraverser.class:

public class ModuleTraverser implements TraverserProvider {


public Traverser get(Node n) {
return n.traverse(
Traverser.Order.BREADTH_FIRST,
StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL_BUT_START_NODE,
RelationShips.HAS_BASIC_ITEM,
Direction.OUTGOING,
RelationShips.HAS_MODULE,
Direction.OUTGOING);
}


}

and my Testcase:

@RunWith(GuiceJunit4ClassRunner.class)
@InjectWith(InjectorProviderA.class)
public class ModuleTraverserTest {
@Inject
DatabaseService ds;
@Inject
Injector injector;

@Before
public void setup() {
ds = injector.getInstance(DatabaseService.class);
}

@After
public void tearDown() {
ds.closeLink();
}

@Test
public void traverserTest() {
Collection l = ds.getObjectGraph().get(Module.class); <---The
ClassCastException is thrown here
System.err.println("asd");
....
}}

I don't know what I'm doing wrong there and hope you can help me.
Thank you a lot.

Best regards,

Stefan

Peter Neubauer

unread,
Jun 24, 2010, 10:19:29 AM6/24/10
to jo4...@googlegroups.com
Hi Stefan,
could you paste even the StackTrace so we can see what class was actually being returned instead of the Module.class?

Cheers,

/peter neubauer

COO and Sales, Neo Technology

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

http://www.neo4j.org               - Your high performance graph database.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.

Stefan Berndt

unread,
Jun 24, 2010, 10:56:34 AM6/24/10
to jo4neo
/home/stefan/jdk1.6.0_20/bin/java -Didea.launcher.port=7538 -
Didea.launcher.bin.path=/home/stefan/idea-IU-95.214/bin -
Dfile.encoding=UTF-8 -classpath /home/stefan/idea-IU-95.214/lib/
idea_rt.jar:/home/stefan/idea-IU-95.214/plugins/junit/lib/junit-
rt.jar:/home/stefan/jdk1.6.0_20/jre/lib/jce.jar:/home/stefan/
jdk1.6.0_20/jre/lib/jsse.jar:/home/stefan/jdk1.6.0_20/jre/lib/
management-agent.jar:/home/stefan/jdk1.6.0_20/jre/lib/deploy.jar:/home/
stefan/jdk1.6.0_20/jre/lib/plugin.jar:/home/stefan/jdk1.6.0_20/jre/lib/
charsets.jar:/home/stefan/jdk1.6.0_20/jre/lib/resources.jar:/home/
stefan/jdk1.6.0_20/jre/lib/alt-rt.jar:/home/stefan/jdk1.6.0_20/jre/lib/
javaws.jar:/home/stefan/jdk1.6.0_20/jre/lib/rt.jar:/home/stefan/
jdk1.6.0_20/jre/lib/ext/localedata.jar:/home/stefan/jdk1.6.0_20/jre/
lib/ext/sunjce_provider.jar:/home/stefan/jdk1.6.0_20/jre/lib/ext/
dnsns.jar:/home/stefan/jdk1.6.0_20/jre/lib/ext/sunpkcs11.jar:/home/
stefan/projekt/graphdb/database/target/test-classes:/home/stefan/
projekt/graphdb/database/target/classes:/home/stefan/.m2/repository/
com/googlecode/guice-junit4/guice-junit4-core/0.1.1/guice-junit4-
core-0.1.1.jar:/home/stefan/.m2/repository/com/google/inject/guice/2.0/
guice-2.0.jar:/home/stefan/.m2/repository/aopalliance/aopalliance/1.0/
aopalliance-1.0.jar:/home/stefan/.m2/repository/junit/junit/4.6/
junit-4.6.jar:/home/stefan/.m2/repository/org/slf4j/slf4j-
log4j12/1.4.3/slf4j-log4j12-1.4.3.jar:/home/stefan/.m2/repository/org/
slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.jar:/home/stefan/.m2/repository/
log4j/log4j/1.2.16/log4j-1.2.16.jar:/home/stefan/.m2/repository/org/
neo4j/neo4j-index/1.1-SNAPSHOT/neo4j-index-1.1-SNAPSHOT.jar:/home/
stefan/.m2/repository/org/neo4j/neo4j-kernel/1.0/neo4j-kernel-1.0.jar:/
home/stefan/.m2/repository/org/apache/geronimo/specs/geronimo-
jta_1.1_spec/1.1.1/geronimo-jta_1.1_spec-1.1.1.jar:/home/stefan/.m2/
repository/org/apache/lucene/lucene-core/2.9.2/lucene-core-2.9.2.jar:/
home/stefan/projekt/graphdb/data/target/classes:/home/stefan/.m2/
repository/com/google/code/guice/guice/2.0.1/guice-2.0.1.jar:/home/
stefan/.m2/repository/cglib/cglib/2.2/cglib-2.2.jar:/home/stefan/.m2/
repository/asm/asm/3.1/asm-3.1.jar:/home/stefan/.m2/repository/com/
googlecode/lambdaj/lambdaj/2.1/lambdaj-2.1.jar:/home/stefan/.m2/
repository/org/hamcrest/hamcrest-all/1.1/hamcrest-all-1.1.jar:/home/
stefan/.m2/repository/org/objenesis/objenesis/1.2/objenesis-1.2.jar:/
home/stefan/.m2/repository/commons-logging/commons-logging/1.1.1/
commons-logging-1.1.1.jar:/home/stefan/.m2/repository/cglib/cglib-
nodep/2.2/cglib-nodep-2.2.jar:/home/stefan/.m2/repository/de/atns/
playground/graphdb/logger/1.0-SNAPSHOT/logger-1.0-SNAPSHOT.jar:/home/
stefan/.m2/repository/thewebsemantic/jo4neo/0.4.1/jo4neo-0.4.1.jar:/
home/stefan/.m2/repository/org/neo4j/neo-utils/1.0-b11-SNAPSHOT/neo-
utils-1.0-b11-SNAPSHOT.jar:/home/stefan/.m2/repository/org/neo4j/neo/
1.0-b11-SNAPSHOT/neo-1.0-b11-SNAPSHOT.jar:/home/stefan/.m2/repository/
org/neo4j/neo-component-commons/0.3-SNAPSHOT/neo-component-commons-0.3-
SNAPSHOT.jar:/home/stefan/.m2/repository/org/neo4j/index-util/0.9-
SNAPSHOT/index-util-0.9-SNAPSHOT.jar
com.intellij.rt.execution.application.AppMain
com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4
guice.ModuleTraverserTest
java.lang.ClassCastException: java.lang.Class cannot be cast to
java.lang.reflect.ParameterizedType
at jo4neo.impl.FieldContext.type2(FieldContext.java:166)
at jo4neo.impl.FieldContext.isPluralPrimitive(FieldContext.java:158)
at jo4neo.impl.LoadOperation.loadDirect(LoadOperation.java:229)
at jo4neo.impl.LoadOperation.loadAll(LoadOperation.java:119)
at jo4neo.impl.LoadOperation.loadAll(LoadOperation.java:69)
at jo4neo.impl.ObjectGraphImpl.get(ObjectGraphImpl.java:131)
at guice.ModuleTraverserTest.traverserTest(ModuleTraverserTest.java:
48)
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:597)
at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:
41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:
20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
70)
at
com.googlecode.guicejunit4.core.GuiceJunit4ClassRunner.runChild(GuiceJunit4ClassRunner.java:
98)
at
com.googlecode.guicejunit4.core.GuiceJunit4ClassRunner.runChild(GuiceJunit4ClassRunner.java:
40)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.junit.runner.JUnitCore.run(JUnitCore.java:159)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:
94)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:
192)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
64)
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:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
115)


On 24 Jun., 16:19, Peter Neubauer <peter.neuba...@neotechnology.com>
wrote:
> Hi Stefan,
> could you paste even the StackTrace so we can see what class was actually
> being returned instead of the Module.class?
>
> Cheers,
>
> /peter neubauer
>
> COO and Sales, Neo Technology
>
> GTalk:      neubauer.peter
> Skype       peter.neubauer
> Phone       +46 704 106975
> LinkedIn  http://www.linkedin.com/in/neubauer
> Twitter      http://twitter.com/peterneubauer
>
> http://www.neo4j.org              - Your high performance graph database.http://www.thoughtmade.com- Scandinavia's coolest Bring-a-Thing party.
>
> On Thu, Jun 24, 2010 at 11:30 AM, Stefan Berndt <gevestber...@googlemail.com

Stefan Berndt

unread,
Jun 25, 2010, 4:59:36 AM6/25/10
to jo4neo
Hello Peter,

I think I understand something wrong here. Was playing with the User-
Role Example and the same problem occurs.

The Structure of User-Role is the following (simplified):

RefNode---User--->NodeId<----User1
| ^
| |
R |----------User2 -------|
o |
l |
e R
|------>NodeId<-----Role1 o
^ ^ l
| | (parent) e
|-------Role2<------------------------|

But I don't see where the Traverser is used.

My structure looks like that (simplified):

ConcreteThing ---
>CT1-----------------------------------------------------------------------------------|
|
| Has
Module
|
|

y
|
Modules------------>M1-----------------------------------------------|
|
^
| |
|
| |
|
|
| | Has Basic Item
| | Has Module
| |
|
| | Has BasicItem
|
|
| |
|-----------------------
>M2 |

| |

|
BasicItems -------------------
>BI1<--------------------------------|
|
|
|
|
|------------------------------------
>BI2<----------------------------------------------------------------------

In my graph there are more then these 3 entitytypes and every entity
can stand in relationship to another entity or to another object of
the same entity.
Now i wanna reach the following:

If I have an entity of ConcreteThing i want to find out on what other
entities it consists. These other entities can also consists on
others. So the traversal depth can really get() high und get doesn't
help me there.

Is there a way to traverse with the help of jo4neo or i have to use
the traverser of neo4j and work with nodes. Thanks for your help a
lot.

Best Regards,

Stefan



Peter Neubauer

unread,
Jun 28, 2010, 3:21:19 AM6/28/10
to jo4...@googlegroups.com
Stefan,
sorry for being slow in response - holiday and Swedish midsummer happening here :)

In the Roles example, the traverser is used to find out all users that are part of certain roles - directly via being part of that role (via "role" relationships), and indirectly via being part of a sub-role (via "parent" relationships, starting at a role node - see http://code.google.com/p/jo4neo/source/browse/trunk/patterns/userroles/src/main/java/example/RoleMembers.java

Your ASCII art is a bit unreadable in my mail browser, so would you care to make a fast chart using e.g. GraphViz or so?


Cheers,

/peter neubauer

COO and Sales, Neo Technology

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

http://www.neo4j.org               - Your high performance graph database.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.

Stefan Berndt

unread,
Jun 28, 2010, 4:35:31 AM6/28/10
to jo4neo
The example with the TraverserProvider i understand.

the problem is f.ex.:

// @neo(traverser= ModuleTraverser.class)
// private Collection elements;
//
// public Collection getElements() {
// return elements;
// }

doesn't work and i get an Exception when i call getElements.
i need traversing through such a graph:
http://picasaweb.google.com/112639720921939285519/UntitledAlbum#5487738459476662642
I need also read out the depth while traversing because i have to
output this structure.
I don't understand why the Exception is thrown.
Do I need to do this in plain neo4j code or does jo4neo helps me
there.

Bets Regards,

Stefan

On 28 Jun., 09:21, Peter Neubauer <peter.neuba...@neotechnology.com>
wrote:
> Stefan,
> sorry for being slow in response - holiday and Swedish midsummer happening
> here :)
>
> In the Roles example, the traverser is used to find out all users that are
> part of certain roles - directly via being part of that role (via "role"
> relationships), and indirectly via being part of a sub-role (via "parent"
> relationships, starting at a role node - seehttp://code.google.com/p/jo4neo/source/browse/trunk/patterns/userrole...
>
> Your ASCII art is a bit unreadable in my mail browser, so would you care to
> make a fast chart using e.g. GraphViz or so?
>
> http://www.graphviz.org/http://www.pixelglow.com/graphviz/
>
> Cheers,
>
> /peter neubauer
>
> COO and Sales, Neo Technology
>
> GTalk:      neubauer.peter
> Skype       peter.neubauer
> Phone       +46 704 106975
> LinkedIn  http://www.linkedin.com/in/neubauer
> Twitter      http://twitter.com/peterneubauer
>
> http://www.neo4j.org              - Your high performance graph database.http://www.thoughtmade.com- Scandinavia's coolest Bring-a-Thing party.
>
> On Fri, Jun 25, 2010 at 10:59 AM, Stefan Berndt <gevestber...@googlemail.com

Taylor Cowan

unread,
Jun 28, 2010, 8:02:42 AM6/28/10
to jo4...@googlegroups.com
Stephan,

the exception is happening in the de-marshal stage of jo4neo and
appears to be either a bug, or a situation where some kind of error or
warning would be helpful.

jo4neo does not help with traversers, but does help in taking the
results of a traverser and converting to java objects.

in your case it looks like jo4neo thinks it found a plural-primitive
field. That means a Collection of some primitive type,
Collection<String> for example...but that's not the case, so when it
attempts to gain the templated type, it's getting a class cast
exception. I think just a look at your bean class would help us
figure out what's going wrong. can you attach or past that class in a
message?

Taylor

Stefan Berndt

unread,
Jun 28, 2010, 8:24:50 AM6/28/10
to jo4neo
ok the problem occurs also in the simplest case with the Relation
Module ---> BasicItem | Module

public class Module {
// ------------------------------ FIELDS
------------------------------


transient Nodeid node;

@neo("HAS_BASIC_ITEM")
private Collection<BasicItem> basicItems = new
ArrayList<BasicItem>();

@neo("HAS_MODULE")
private Collection<Module> modules = new ArrayList<Module>();
@neo(index = true)
private String name;

@neo(traverser= ModuleTraverser.class)
private Collection elements;

// --------------------------- CONSTRUCTORS
---------------------------

public Module() {
}


public Module(String name) {
this.name = name;
}

// --------------------- GETTER / SETTER METHODS ---------------------

public Collection<BasicItem> getBasicItems() {
return Collections.unmodifiableCollection(basicItems);
}



public Collection getElements() { //TODO für Traverser
unbedingt andere Struktur
return Collections.unmodifiableCollection(elements);
}

public Collection<Module> getModules() {
return Collections.unmodifiableCollection(modules);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Nodeid getNode() {
return node;
}

// ------------------------ CANONICAL METHODS ------------------------

@Override
public String toString() {
return "Module{" +
"name='" + name + '\'' +
", node=" + node.id() +
'}';
}

// -------------------------- OTHER METHODS --------------------------

public void addBasicItem(BasicItem bi) {
basicItems.add(bi);
}

public void addModule(Module m) {
modules.add(m);
}



// -------------------------- INNER CLASSES --------------------------

public class ModuleTraverser implements TraverserProvider {
public Traverser get(Node n) {
return n.traverse(
Traverser.Order.BREADTH_FIRST,
StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL_BUT_START_NODE,
RelationShips.HAS_BASIC_ITEM,
Direction.OUTGOING,
RelationShips.HAS_MODULE,
Direction.OUTGOING) ;
}
}
}

public class BasicItem {
// ------------------------------ FIELDS
------------------------------

@neo(index = true)
private String name;

private transient Nodeid node;

// --------------------------- CONSTRUCTORS
---------------------------


@Override
public String toString() {
return "BasicItem{" +
"node=" + node.id() +
", name='" + name + '\'' +
'}';
}

public BasicItem() {
}

public BasicItem(String name) {
this.name = name;
}

// --------------------- GETTER / SETTER METHODS ---------------------

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Nodeid getNode() {
return node;
}
}

I think the Problem is, that there are two types of JavaObject
(BasicItem, Module).
If i just traverse for BasicItem (Relationship: HAS_BASIC_ITEM) all
works fine. Now I'm thinking about using a superclass or or interface
somethinglike GraphObject to ensure typesafety, but i'm not sure if
this work as i want. Maybe you can help me.

On 28 Jun., 14:02, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Stephan,
>
> the exception is happening in the de-marshal stage of jo4neo and
> appears to be either a bug, or a situation where some kind of error or
> warning would be helpful.
>
> jo4neo does not help with traversers, but does help in taking the
> results of a traverser and converting to java objects.
>
> in your case it looks like jo4neo thinks it found a plural-primitive
> field.  That means a Collection of some primitive type,
> Collection<String> for example...but that's not the case, so when it
> attempts to gain the templated type, it's getting a class cast
> exception.  I think just a look at your bean class would help us
> figure out what's going wrong.  can you attach or past that class in a
> message?
>
> Taylor
>
> On Mon, Jun 28, 2010 at 3:35 AM, Stefan Berndt
>
> <gevestber...@googlemail.com> wrote:
> > The example with the TraverserProvider i understand.
>
> > the problem is f.ex.:
>
> > //    @neo(traverser= ModuleTraverser.class)
> > //    private Collection elements;
> > //
> > //    public Collection getElements() {
> > //        return elements;
> > //    }
>
> > doesn't work and i get an Exception when i call getElements.
> > i need traversing through such a graph:
> >http://picasaweb.google.com/112639720921939285519/UntitledAlbum#54877...
> >>http://www.neo4j.org             - Your high performance graph database.http://www.thoughtmade.com-Scandinavia's coolest Bring-a-Thing party.

Stefan Berndt

unread,
Jun 28, 2010, 8:37:48 AM6/28/10
to jo4neo
Peter gave an example in this thread:
http://groups.google.com/group/jo4neo/browse_thread/thread/ef37a922132bd413

public enum RelationTypes implements RelationshipType
{
EXAMPLE_ROLE ("example.Role"),
EXAMPLE_USER ("example.User");

String name = "dummy";
private RelationTypes(String name)
{
this.name = name;
}
public String getName() {
return name;
}

} but this does not work.
an Enum does only accept Strings isn't it so?
> > >>http://www.neo4j.org             - Your high performance graph database.http://www.thoughtmade.com-Scandinavia'scoolest Bring-a-Thing party.
> ...
>
> Erfahren Sie mehr »

Taylor Cowan

unread,
Jun 28, 2010, 9:08:24 AM6/28/10
to jo4...@googlegroups.com
Thanks for the code. jo4neo uses the method signature. It wants/needs to know the type.

Collection<?>

Sent from my HTC

-----Original Message-----
From: Stefan Berndt <gevest...@googlemail.com>
Sent: 28 June 2010 3:35 AM
To: jo4neo <jo4...@googlegroups.com>
Subject: Re: Problem with Traversing

The example with the TraverserProvider i understand.

the problem is f.ex.:

// @neo(traverser= ModuleTraverser.class)
// private Collection elements;
//
// public Collection getElements() {
// return elements;
// }

doesn't work and i get an Exception when i call getElements.
i need traversing through such a graph:

http://picasaweb.google.com/112639720921939285519/UntitledAlbum#5487738459476662642

Bets Regards,

Stefan

> http://www.neo4j.org              - Your high performance graph database.http://www.thoughtmade.com- Scandinavia's coolest Bring-a-Thing party.


>
> On Fri, Jun 25, 2010 at 10:59 AM, Stefan Berndt <gevestber...@googlemail.com
>
> > wrote:
> > Hello Peter,
>
> > I think I understand something wrong here


[The entire original message is not included]

Stefan Berndt

unread,
Jun 28, 2010, 9:58:50 AM6/28/10
to jo4neo
hmmm ok :-(

so I'm now traversing over the nodes with plain neo4j.

public Collection traverseOverModule(Module m) {

Traverser trav =
gdb.getNodeById(m.getNode().id()).traverse(Traverser.Order.BREADTH_FIRST,
StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL_BUT_START_NODE,
RelationShips.HAS_BASIC_ITEM,Direction.OUTGOING,
RelationShips.HAS_MODULE,Direction.OUTGOING);
return trav.getAllNodes();

That works but i have again the nodes. How can jo4neo help me here.



On 28 Jun., 15:08, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Thanks for the code. jo4neo uses the method signature.  It wants/needs to know the type.
>
> Collection<?>
>
> Sent from my HTC
>
> -----Original Message-----
> From: Stefan Berndt <gevestber...@googlemail.com>
> Sent: 28 June 2010 3:35 AM
> To: jo4neo <jo4...@googlegroups.com>
> Subject: Re: Problem with Traversing
>
> The example with the TraverserProvider i understand.
>
> the problem is f.ex.:
>
> //    @neo(traverser= ModuleTraverser.class)
> //    private Collection elements;
> //
> //    public Collection getElements() {
> //        return elements;
> //    }
>
> doesn't work and i get an Exception when i call getElements.
> i need traversing through such a graph:http://picasaweb.google.com/112639720921939285519/UntitledAlbum#54877...
> >http://www.neo4j.org             - Your high performance graph database.http://www.thoughtmade.com-Scandinavia's coolest Bring-a-Thing party.

Taylor Cowan

unread,
Jun 28, 2010, 10:27:19 AM6/28/10
to jo4...@googlegroups.com
Stefan,

I suspect that in your original example, if you were to type your
Collection like this:

Collection<Object> getElements(...)

In your example, it's just

Collection getElements()

On my end I need to add logic to detect missing generics and warn the
user so that the problem isn't obtuse and confusing...as well as
document this clearly. Please type this Collection<....> and give it
another try.

The idea behind traverser support in jo4neo is that sometimes, you
want to bring in part of the graph into your object as a collection of
child items. NEO4J traversers just walk the graph, perhaps you want
to filter out unmatching types...like in my user/roles example, you
only want roles, ignore the users...your traverser collection would
be:

Collection<Role> getRoles()...

Then jo4neo will take the traverser you provided, and ignore any nodes
that cannot be coerced as type "Role". The exception happens because
your method gives no generic type. Ideally you'd want to type it as
something a little more specific as opposed to "Object", maybe Element
or BaseElement, whatever makes the most sense in your domain.

Taylor

Taylor Cowan

unread,
Jun 28, 2010, 3:03:49 PM6/28/10
to jo4...@googlegroups.com
Stephan,

Please see http://code.google.com/p/jo4neo/source/browse/#svn/trunk/jo4neo/src/test/java/test/traverser

I used your code to create a simple test case. Notice my traverser is
restricted to Object. If you'd like to filter that set, give it
another type. I had to make a few changes:

1. Collections without a generic type specifier cause jo4neo to bomb.
You'd think the default would be of type Object, but that's not the
case with Java, if no generic type is given, the introspection finds
none. So the test case just starts with Collection<Object>. You can
restrict that as needed.

2. I moved the annonymous inner type out. The Traverser providers
need to be beans in the strict sense. Jo4neo needs to instantiate
them using a visible default constructor.

Hope that helps. Thanks for providing the code for us, it made it
easier for me to construct this example. Hope to hear back on how it
goes.

Taylor

On Mon, Jun 28, 2010 at 8:58 AM, Stefan Berndt
<gevest...@googlemail.com> wrote:

Stefan Berndt

unread,
Jun 29, 2010, 6:30:48 AM6/29/10
to jo4neo
Have a big thanks it works now fine on my other beans. i have to adapt
these objectstructure and the traversers on my needs a littlebit but i
know now how it works.

Best regards,

Stefan

On 28 Jun., 21:03, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Stephan,
>
> Please seehttp://code.google.com/p/jo4neo/source/browse/#svn/trunk/jo4neo/src/t...
>
> I used your code to create a simple test case.  Notice my traverser is
> restricted to Object.  If you'd like to filter that set, give it
> another type.  I had to make a few changes:
>
> 1. Collections without a generic type specifier cause jo4neo to bomb.
> You'd think the default would be of type Object, but that's not the
> case with Java, if no generic type is given, the introspection finds
> none.  So the test case just starts with Collection<Object>.  You can
> restrict that as needed.
>
> 2. I moved the annonymous inner type out.  The Traverser providers
> need to be beans in the strict sense.  Jo4neo needs to instantiate
> them using a visible default constructor.
>
> Hope that helps.  Thanks for providing the code for us, it made it
> easier for me to construct this example.  Hope to hear back on how it
> goes.
>
> Taylor
>
> On Mon, Jun 28, 2010 at 8:58 AM, Stefan Berndt
>
> >> >http://www.neo4j.org             - Your high performance graph database.http://www.thoughtmade.com-Scandinavia'scoolest Bring-a-Thing party.

Stefan Berndt

unread,
Jun 29, 2010, 6:29:00 AM6/29/10
to jo4neo
Hey this helped much. Traversing works now. I have applied Traversing
now on my other beans and this works fine too.
I have to adapt it now to my need a little bit, but i think there will
not come more problems. Have a big thanks!

Best Regards,

Stefan

On 28 Jun., 21:03, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Stephan,
>
> Please seehttp://code.google.com/p/jo4neo/source/browse/#svn/trunk/jo4neo/src/t...
>
> I used your code to create a simple test case.  Notice my traverser is
> restricted to Object.  If you'd like to filter that set, give it
> another type.  I had to make a few changes:
>
> 1. Collections without a generic type specifier cause jo4neo to bomb.
> You'd think the default would be of type Object, but that's not the
> case with Java, if no generic type is given, the introspection finds
> none.  So the test case just starts with Collection<Object>.  You can
> restrict that as needed.
>
> 2. I moved the annonymous inner type out.  The Traverser providers
> need to be beans in the strict sense.  Jo4neo needs to instantiate
> them using a visible default constructor.
>
> Hope that helps.  Thanks for providing the code for us, it made it
> easier for me to construct this example.  Hope to hear back on how it
> goes.
>
> Taylor
>
> On Mon, Jun 28, 2010 at 8:58 AM, Stefan Berndt
>
> >> >http://www.neo4j.org             - Your high performance graph database.http://www.thoughtmade.com-Scandinavia'scoolest Bring-a-Thing party.

Stefan Berndt

unread,
Jun 29, 2010, 6:28:51 AM6/29/10
to jo4neo
Hey this helped much. Traversing works now. I have applied Traversing
now on my other beans and this works fine too.
I have to adapt it now to my need a little bit, but i think there will
not come more problems. Have a big thanks!

Best Regards,

Stefan

On 28 Jun., 21:03, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Stephan,
>
> Please seehttp://code.google.com/p/jo4neo/source/browse/#svn/trunk/jo4neo/src/t...
>
> I used your code to create a simple test case.  Notice my traverser is
> restricted to Object.  If you'd like to filter that set, give it
> another type.  I had to make a few changes:
>
> 1. Collections without a generic type specifier cause jo4neo to bomb.
> You'd think the default would be of type Object, but that's not the
> case with Java, if no generic type is given, the introspection finds
> none.  So the test case just starts with Collection<Object>.  You can
> restrict that as needed.
>
> 2. I moved the annonymous inner type out.  The Traverser providers
> need to be beans in the strict sense.  Jo4neo needs to instantiate
> them using a visible default constructor.
>
> Hope that helps.  Thanks for providing the code for us, it made it
> easier for me to construct this example.  Hope to hear back on how it
> goes.
>
> Taylor
>
> On Mon, Jun 28, 2010 at 8:58 AM, Stefan Berndt
>
> >> >http://www.neo4j.org             - Your high performance graph database.http://www.thoughtmade.com-Scandinavia'scoolest Bring-a-Thing party.
Reply all
Reply to author
Forward
0 new messages