cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikita Timofeev <ntimof...@objectstyle.com>
Subject Re: Question on how to properly create parent-child nested dependent objects?
Date Mon, 18 Sep 2017 15:40:01 GMT
Hi Andrew,

Can you provide stack trace for the exception you got (Cayenne related
part of it)?
It seems to me that you have problem with PK generation, not with your
data objects.
Your code looks fine to me and should work.

On Mon, Sep 18, 2017 at 6:30 PM, Andrew Willerding
<awillerding@itsurcom.com> wrote:
> Hi,
>
> I am trying to create a DB record where a dependency record may not yet
> exist and I'm getting a "No rows for ..." error.  I don't understand how I
> should create the child record that will be used for the parent object so it
> can be referenced by the parent object without getting an error.  The idea
> is to dynamically create a child record as needed.
>
> Thanks,
>
> Andrew
>
> Example code:
>
> ObjectContext oc = ClientBaseAdmin.getObjectContext();
> CommunicationLog cl = oc.newObject(CommunicationLog.class);
> cl.setCommunicationDT(LocalDateTime.now());
> cl.setCommunicationType(CommunicationType.find("Email"));
> oc.commitChanges();
>
> and in CommunicationType I have
>
> public static CommunicationType find(String value) {
>         CommunicationType result = null;
>         result = ObjectSelect.query(CommunicationType.class)
>                 .where(CommunicationType.DESCRIPTION.eq(value))
>                 .selectFirst(ClientBaseAdmin.getObjectContext());
>
>         if (result == null) {
>             CommunicationType ct =
> ClientBaseAdmin.getObjectContext().newObject(CommunicationType.class);
>             ct.setDescription(value);
>             ClientBaseAdmin.getObjectContext().commitChanges();
>             result = ct;
>         }
>         return result;
> }
>



-- 
Best regards,
Nikita Timofeev

Mime
View raw message