Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:50:50+00:00 2026-06-15T18:50:50+00:00

I have insert some node into Neo4j DB.And I want to select some node

  • 0

I have insert some node into Neo4j DB.And I want to select some node from database and cast it to specific class.

Here are some code about the problem:

class Service {
    Neo4jTemplate neo4jTemplate

    @Transactional
    def find() {
        def id1 = 11
        //Knowledge k = neo4jTemplate.findOne(1, Knowledge)
        Result result = neo4jTemplate.query("start n=node(11) return ID(n),n.name,n.age;", null)
    //how to cast the result to User class
        println "the tpye of result called User is  "+   result.to(User.class).is(cn.edu.bnuz.itc.bok.sub2.User.class)
    }

}

The detail about node like :

+-------------------------------------------------------------------------+
| Node[11]{career:"programmer",name:"kelvin",age:35,introduce:"lazy doy"} |
+-------------------------------------------------------------------------+

        @NodeEntity
        class User {
        @GraphId
        Long id;
        String name;
        int age;
}

I just want get the node’s id, name, age from db and put it into a User class.
But it failed many time with many method.

Here I have encounter a problem which is :How can I cast the result to my target class? I have try many method to cast but fail finally.Thank you for you attention.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:50:52+00:00Added an answer on June 15, 2026 at 6:50 pm

    Return the user node from the query and call the to method of the returned Result with the desired class as argument:

    Result result = neo4jTemplate.query("start n=node(11) return n", null);
    for(User u : result.to(User.class)) {
        doSomethingWith(u);
    }
    

    You may want to consider using repositories that support cypher queries like:

    public interface UserRepository extends GraphRepository<User> {
        @Query("start n=node(11) return n")
        Iterable<User> getUser11();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that is trying to insert some data into an SQL
i have a little difficulty in understanding how to do some INSERT SELECT. For
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have some data enclosed in HTML tags. I want to insert this data
In Drupal, if you want to insert something into the node table, 'nid' can
I have function that has to write some data into database table, but after
Below is the code example for the insert code of a node into a
I have to update some nodereference fields from custom code in myModule. This has
I have a ModelAdmin where I need to insert some html-snippet that is not
I have insert.php verify.php in Insert.php I have a form with some fields and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.