You must define a Primary Key class of your own.

I'd suggest to take the 'PrimaryKey Example - Multiple Field' from the 
Datanucleus Guide [1] as a starting point, but improve the marshalling logic 
such that arbitrary strings within your PK columns are possible:

I believe, using ',' as the separator should not conflict with other logic;


private final static String SEPARATOR = ",";


/**
 * Constructor accepting same input as generated by toString().
 */
public ComposedIdKey(String value)
{
        StringTokenizer token = new StringTokenizer (value, SEPARATOR);
        this.targetClassName = token.nextToken();
        this.field1 = new String(Base64.getDecoder().decode(token.nextToken()));
        this.field2 = new String(Base64.getDecoder().decode(token.nextToken()));
}

..

public String toString ()
{
        // Give output expected by String constructor
        
        final String left  = Base64.getEncoder().encodeToString(this.field1);
        final String right = Base64.getEncoder().encodeToString(this.field2);
        
        return this.targetClassName + this.field1 + SEPARATOR + this.field2;
}

[1] http://www.datanucleus.org/products/accessplatform/jpa/mapping.html#identity

On 2018/06/21 20:09:20, Brian K <[email protected]> wrote: 
> Hello,
> 
> 
> 
> I’m modeling my domain objects over an existing sql server database.  One
> of my tables has a primary key that has two columns of type char(10).  The
> values that come from columns like this appear with trailing spaces.  The
> OID generated by Isis for a single column primary key works fine and shows
> urls such as
> http://localhost:8080/wicket/entity/dbo.courtcd:s_3AN-P%20%20%20%20%20 .
> 
> 
> When I have a table that has two fields like this as the primary key, I get
> this error:
> 
> Could not parse OID
> 'dbo.crtprecx:domainapp.modules.simple.dom.impl.CourtPrecinct_PK_3AN-P
>     :ANCHORAGE '; should match pattern:
> ^((([!*])?([^:~$\^#]+):([^:~$\^#]+))((~[^:~$\^#]+:[^:~$\^#]+)*))([$][^:~$\^#]+)?([\^](\d+):([^:~$\^#]+)?:(\d+)?)?$
> 
> Do I have to now create a primary key class to use the trimmed values
> of the string fields in the primary key, or is there another way to
> handle this?
> 
> Thank you!
> 
> Brian
> 

Reply via email to