问题
Let's exemplify
- I receive a Vertex with Tinkerpop Blueprint, then I use Frames to convert it in an entity.
- I close the database (so from now the node is detached from the DB)
- and I show the node on a web page to let the user modify it.
The user makes some modifications, then I shoud persist the changes.
The problem is that the Instance of the database is already closed, so the entity is detached from the database: What is the best practice (considering performance and memory usage too) to update the node?
This may be the code example:
FramedGraph<OrientGraph> graph = factory.getFramedGraph();
User user = graph.addVertex(null, User.class);
graph.shutdown();
then I want to update later the node:
user.name = "Donald Duck";
user.... ?
Thank you, Andrea
回答1:
I found this way, that seems quite efficient:
public User persistUser(User user){
FramedGraph<OrientGraph> graph = factory.getFramedGraph();
user = graph.frame(user.asVertex(), User.class);
factory.persist();
graph.shutdown();
So the framework automatically merge back the entity to the database. Then you have to persist.
来源:https://stackoverflow.com/questions/26187415/what-is-the-best-practice-to-update-a-vertex-after-is-detached-from-db-with-tink