Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not persisting to JanusGraph #54

Open
oodles-arvind-das opened this issue Oct 19, 2018 · 8 comments
Open

Not persisting to JanusGraph #54

oodles-arvind-das opened this issue Oct 19, 2018 · 8 comments

Comments

@oodles-arvind-das
Copy link

oodles-arvind-das commented Oct 19, 2018

I am trying to use ferma ORM for my project . Current problem is, I am not able to persist my entities to JanusGraph DB.
Here is my code Required :
Entity Class




public abstract class Person extends AbstractVertexFrame {
    private String id;
    private String name;
    private int age;
    private String mobile;

    @Property("age")
    public abstract int getAge();

    @Property("age")
    public abstract void setAge(int age) ;

    @Property("mobile")
    public abstract String getMobile();

    @Property("mobile")
    public abstract void setMobile(String mobile) ;

    public String getId() {
        return id;
    }

    @Property("name")
    public abstract String getName() ;

    @Property("name")
    public abstract  void setName(String name);

    public String toString(){
        return this.name+" has Id"+this.getId();
    }
}

This is how I create/initialize my DelegatedFramedGraph bean:

@Bean
    FramedGraph framedGraph(JanusGraph graph,GremlinBeanPostProcessor gremlinBeanPostProcessor){
        return new DelegatingFramedGraph(graph,true,gremlinBeanPostProcessor.getEntityClasses());
    }

JanusGraph is initialized :

@Bean
    JanusGraph graph(JanusGremlinGraphFactory janusGremlinGraphFactory){
        JanusGraph janusGraph = null;
        janusGraph = janusGremlinGraphFactory.openGraph();
        return janusGraph;
    }

    @Bean
    JanusGremlinGraphFactory janusGremlinGraphFactory(){
        JanusGremlinGraphFactory jggf;
        jggf = new JanusGremlinGraphFactory();
        jggf.setConfiguration(getConfiguration());
        return jggf;
    }

When I try to persist it:

 @Autowired
    private FramedGraph framedGraph;

public String savePerson(String name,int age,String mobile){
        Person person =  framedGraph.addFramedVertex(Person.class);
        person.setName(name);
        person.setAge(age);
        person.setMobile(mobile);
        System.out.println(person.getName()+"and person id is"+person.getId());
        return person.toString();
    }

Nothing is stored to JanusGraph, not sure where is the problem.

Can somebody help me ?

@oodles-arvind-das
Copy link
Author

My bad, I made a basic mistake , I had to perform:
framedGraph.tx().commit();

This should be the part of FramedGraph on every add and other operations. The only thing left is , I did not get the Id property back.

@syncleus-bot
Copy link

syncleus-bot commented Oct 19, 2018 via email

@oodles-arvind-das
Copy link
Author

Thanks , can you guide me how can I get the currently saved object's Id back ?
Commit is a void operation and it does not return anything and also transaction is closed. Getting id property which is assigned by the graph is highly needed.

@freemo
Copy link
Member

freemo commented Oct 19, 2018 via email

@oodles-arvind-das
Copy link
Author

Got it, had to tinker a little, I should not be running too fast in asking questions without having tried out everything, but got it fixed.

person.getElement().id()

Since usage of Spring Framework wraps you in chains and you always expect that id returned from DB is automatically mapped to the id property of the entity, that took some time for me to come out of that world.

@oodles-arvind-das
Copy link
Author

oodles-arvind-das commented Oct 19, 2018

Though this thread is closed now, I saw a behavior here, If I have my non abstract class and then ofcourse non abstract properties, ferma persists the node but not the properties. Is that the expected behavior ?

Following class is persisted without properties

public class Post extends AbstractVertexFrame {


    private String id;
    private String title;
    private String description;
    private LocalDate dateCreated;




    public String getTitle(){
        return this.title;
    }


    public void setTitle(String title){
        this.title = title;
    }


    public String getId(){
        return id;
    }


    public void setId(String id){
        this.id = id;
    }


    public  String getDescription() {
        return this.description;
    }


    public  void setDescription(String description){
        this.description = description;
    }

    public  LocalDate getDateCreated() {
        return this.dateCreated;
    }


    public  void setDateCreated(LocalDate localDate){
        this.dateCreated = localDate;
    }

    public String toString(){
        return this.getTitle()+" has Id"+this.getId();
    }
}```




@oodles-arvind-das
Copy link
Author

Though this thread is closed now, I saw a behavior here, If I have my non abstract class and then ofcourse non abstract properties, ferma persists the node but not the properties. Is that the expected behavior ?

Following class is persisted without properties

public class Post extends AbstractVertexFrame {


    private String id;
    private String title;
    private String description;
    private LocalDate dateCreated;




    public String getTitle(){
        return this.title;
    }


    public void setTitle(String title){
        this.title = title;
    }


    public String getId(){
        return id;
    }


    public void setId(String id){
        this.id = id;
    }


    public  String getDescription() {
        return this.description;
    }


    public  void setDescription(String description){
        this.description = description;
    }

    public  LocalDate getDateCreated() {
        return this.dateCreated;
    }


    public  void setDateCreated(LocalDate localDate){
        this.dateCreated = localDate;
    }

    public String toString(){
        return this.getTitle()+" has Id"+this.getId();
    }
}```

From the documentation this works


public class Post extends AbstractVertexFrame {


    private String id;
    private String title;
    private String description;
    private LocalDate dateCreated;




    public String getTitle(){
       return getProperty("title");
    }


    public void setTitle(String title){
        setProperty("title",title);
    }


    public String getId(){
        return id;
    }


    public void setId(String id){
        this.id = id;
    }


    public  String getDescription() {
        return getProperty("description");
    }


    public  void setDescription(String description){
       setProperty("description",description);
    }

    public  LocalDate getDateCreated() {
        return getProperty("dateCreated");
    }


    public  void setDateCreated(LocalDate localDate){
        setProperty("dateCreated",localDate);
    }

    public String toString(){
        return this.getTitle()+" has Id"+this.getId();
    }
}

But why there is so much boilerplate code for getProperty and setProperty, and Post class instance is not able to have its own states, everything is driven by behavior (methods) and states are attained by the @Property annotation .

Please help me understanding that .

@stozk
Copy link

stozk commented Aug 10, 2019

I just encountered the same problem, the @Property annotation didn't work, using setters/getters with setProperty works.

Edit: It seems that the @Property annotions (or annotations in general?) only work when the graphelement class is defined as an abstract class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants