Java Nested Builders being built on insert?

234 views
Skip to first unread message

users ....

unread,
Nov 2, 2011, 12:24:37 PM11/2/11
to Protocol Buffers
I am working on a solution to basically allow me to persist any
protocol buffer with hibernate. However, I have run into a challenge
with nested builders. In order for hibernate to create relationships
it's requiring the parent object be referenced. For these purpose I
wanted the parent object to be a builder. However, in the case of a
nested repeated message field (see example below), upon adding the
builder to the parent the generated code actually builds the object.
You can start to work around this for one level nesting but beyond
that it's really ugly.

message Parent {

repeated Child = 1;
}

message Child {
repeated GrandChild = 1;
}

message GrandChild {
optional int32 id = 1;
}

The problem is that hibernate want's linkage between Java objects and
the builder to message conversions actually destroy this
relationship. My question is why are the objects being built before I
call build and is there any way to fix this? I'd be happy if they
would all be builders until the parent build call is made.

Thanks,

Mike

Pherl Liu

unread,
Nov 7, 2011, 3:41:57 AM11/7/11
to users ...., Protocol Buffers
Can you use addChildBuilder() API for the repeated field, and then call addGrandChildBuilder() in the returned builder?


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Reply all
Reply to author
Forward
0 new messages