There's also this set of utilities to convert an object to a String ID and back:
https://github.com/apache/cayenne/tree/master/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/id
It uses the format like "MyEntity:1:2:3" and IIRC does not attempt to perform
separator escaping for char ID values. Feel free to use it as is, or copy the
code and create your own format.
Andrus
> On Dec 12, 2017, at 2:24 PM, Michael Gentry <[email protected]> wrote:
>
> Hi Ken,
>
> I had some code somewhere that did this, but can't find it offhand.
>
> Nutshell version, I was storing the information in this format:
>
> EntityName:KeyName:KeyValue
>
> You can get that information from the Cayenne[1] (or DataObjectUtils if on
> 3.0) helper class. That format requires a single PK and likewise a single
> integer PK value.
>
> When I needed the object back, I split on the colons and used the parts to
> construct a new ObjectId(entityName, key, value) and passed that to
> Cayenne.objectForPK(context, objectId).
>
> mrg
>
> [1] http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/Cayenne.html
>
>
>
> On Tue, Dec 12, 2017 at 1:44 PM, Ken Anderson <[email protected]>
> wrote:
>
>> Everyone,
>>
>> I’ve been looking around the Cayenne API, but have not been able to find a
>> way to serialize an object ID into a string, and then turn that string back
>> into an object ID or object. What’s the best/right way to do this? For
>> instance, if you want to store a reference to a database object in a text
>> file…
>>
>> Thanks,
>> Ken
>> Confidentiality Notice: This e-mail and accompanying documents contain
>> confidential information intended for a specific individual and purpose.
>> This e-mailed information is private and protected by law. If you are not
>> the intended recipient, you are hereby notified that any disclosure,
>> copying, or distribution, or the taking of any action based on the contents
>> of this information, is strictly prohibited.
>>