0

I'm trying to embed an entity named Data into another one called Workflow.

I'm tying to obtain something like this:

{  
   "_id" : ObjectId("my-object-id"),
   "myproperty" : "myvalue",
   "data":{  
      "category":"DataStore",
      "cullTime":false,
      "cullSpace":false,
      "faveColor":"#449d44",
      "faveShape":"ellipse",
      "filter":false,
      "id":"s1",
      "name":"Source",
      "type":"Rainfall"
   }

}

I setted up my entities as follows:

@Embeddable
public class Data{

    private String category; 
    private String faveColor;
    private String faveShape;
    private String id;
    /* and so on with getters and setters */

In my Workflow entity I have:

@Entity
@Table(name = "workflows")
public class Workflow { 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableGenerator(name = "workflows")  
    private ObjectId id;
    public String getId() { return id.toString(); }
    public void setId(ObjectId id) { this.id = id; }             
    @Embedded
    private Data data; 
    /* and so on with getters and setters */

Inside my db service I have:

Session s = HibernateUtil.getSessionFactory().openSession();
Workflow w = (Workflow) s.get(Workflow.class, new ObjectId(UUID));
w.setData(data);
s.update(w);

The outcome of s.update(obj) is successfull but the changes do not persist on the database.

Thank you for your help.

1 Answers1

0

I solved by flushing the session after update.

s.update(w);
s.flush();