It's true that you wouldn't be able to take advantage of the JPA annotations. However, I'd imagine JPA provides a lower-level API that lets you use it with objects that aren't annotated.
On Wed, Sep 15, 2010 at 8:41 AM, Roberto Caldas <roberto.cal...@gmail.com>wrote: > > If you're using the reflection API correctly, that shouldn't be > necessary. > There is something very wrong here, because I just can't see this :( I > must have a simple POJO Person.java with JPA annotations in it, I cannot > persist a byte array of my message, otherwise I wouldn't be able to make SQL > queries on it. So, this class Person.java is not the class generated by > protoc, I have another class PersonMessage.java generated by protoc and I > want to copy all the values from an PersonMessage instance to a Person > instance. Both classes have attributes with the same name. > I didn't succed to do this with reflections, I would have to write a > considerably complex code to cover all the cases (all types of fields inside > the protobuf: messages inside messages, array of messages inside the > message, etc), as I see, it's not just a question of iterating over a Map of > fields. > > > >For existing java beans, http://code.google.com/p/protostuff might be > able to help. > This is nice, it resolves the problem for the java side, but I still have > the same problem on my client that uses C# :( > > Thanks > > > > On Wed, Sep 15, 2010 at 3:10 AM, David Yu <david.yu....@gmail.com> wrote: > >> For existing java beans, http://code.google.com/p/protostuff might be >> able to help. >> >> On Tue, Sep 14, 2010 at 8:27 PM, Roberto Caldas <roberto.cal...@gmail.com >> > wrote: >> >>> Yes, I tried to use the reflection API, but this doesn't seem right to me >>> because I have to mantain 3 classes for the same entity. When I add a new >>> attribute I'll have to update 3 files! I know I really cannot use JPA with >>> the java code generated by protoc, but using the reflection API the best >>> way? I was used to a java-only world where I could automatically transform >>> my objects into xml messages having only one class representing one entity >>> for all project. >>> >>> About my try on the reflection API, I did not succed and I posted one >>> question about it, could you please help me? I understood that I had to use >>> the protobuf reflection together with java reflection: >>> >>> http://groups.google.com/group/protobuf/browse_thread/thread/add9295e2151481e >>> >>> Thank you for your reply. >>> >>> >>> >>> >>> On Tue, Sep 14, 2010 at 3:19 PM, Kenton Varda <ken...@google.com> wrote: >>> >>>> I'm not all that familiar with JPA, but my guess is that applying JPA to >>>> a protocol buffer type is going to be much less efficient than using >>>> protobuf's native encoding. So you probably want to be serializing your >>>> protobufs with .toByteArray() and then persisting that. >>>> >>>> Failing that, you might want to look at the protobuf reflection API (not >>>> to be confused with java reflection) to see if it might be part of a >>>> solution: >>>> >>>> http://code.google.com/apis/protocolbuffers/docs/reference/java/com/google/protobuf/Message.html >>>> >>>> >>>> <http://code.google.com/apis/protocolbuffers/docs/reference/java/com/google/protobuf/Message.html>E.g. >>>> maybe you could call message.getAllFields() and then feed the data into JPA >>>> somehow. >>>> >>>> On Mon, Sep 13, 2010 at 12:09 PM, roberto_sc >>>> <roberto.cal...@gmail.com>wrote: >>>> >>>>> Hi >>>>> >>>>> I have a basic question about how to organize my project. >>>>> I have a client running C# code, a server running Java code and I >>>>> intend to use protocol buffers to exchange data. >>>>> I thought I could use the .proto file to describe the classes of my >>>>> datamodel and generate .java and .cs and then use these generated src >>>>> as my datamodel. But protoc generate code for message exchange and >>>>> cannot be edited, for example, I cannot generate java code for my >>>>> Person class and add the annotations to persist using JPA. >>>>> >>>>> So, the question is, do I have to mantain 3 files - .java, .cs >>>>> and .proto - that represent the same thing? >>>>> >>>>> Thanks >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Protocol Buffers" group. >>>>> To post to this group, send email to proto...@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com> >>>>> . >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/protobuf?hl=en. >>>>> >>>>> >>>> >>> >>> >>> -- >>> virtus in medium est >>> . >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Protocol Buffers" group. >>> To post to this group, send email to proto...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/protobuf?hl=en. >>> >> >> >> >> -- >> When the cat is away, the mouse is alone. >> - David Yu >> > > > > -- > virtus in medium est > . > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.