cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Custom types in PKs and relationships
Date Mon, 23 Jul 2012 19:04:13 GMT
From analyzing Kanwar's project, I was able to reproduce ClassCastException in an isolated
unit test (see CAY-1728). The cause is essentially the same as FaultFailureException for the
same mapping (more on that below). Whether ClassCastException or FaultFailureException is
thrown depends on the order of internal iteration over properties for a given entity (the
relative order of attributes and relationships in ClassDescriptor.getDeclaredProperties()
which is driven by HashMap key hashing algorithm, i.e. completely obscure to the user). 

But ignore all that for a moment... The cause is that Cayenne is confused by mapping "redundancy"
- there's a meaningful PK that uses custom type , and that same PK is used as a key in a to-many
relationship (where Cayenne can't figure out custom type reliably, and uses default type).

So what to do about it? We have a long term solution to change type mapping strategy that
we are likely to implement in Cayenne 3.2: .
Until that happens my advice would be to avoid using custom types for meaningful PKs. E.g.
map it as a String and add a pair of extra methods to convert between String and UUID:

// ignoring possibility of NULLs for a moment...
public UUID getUserMasterUUID() {
  return UUID.fromString(getUserMasterId());

public void setUserMasterUUID(UUID uuid) {

Not ideal, but should immediately solve your problem. And over time this will get fixed in


On Jul 23, 2012, at 10:20 AM, Kanwar Manish wrote:

> Hi Andrus
> I am working on a small sample project with a new database. I will send you
> the details shortly complete with all the details.
> For  now - one tit-bit of information is that this problem doesn't seem to
> be in 3.0.2 but in 3.1B1.
> Will mail shortly.
> Thanks
> Manish
> On Sun, Jul 22, 2012 at 2:57 PM, Andrus Adamchik <>wrote:
>> So we have 2 parallel mailing list thread discussing as I suspect the same
>> underlying problem:
>> 1. "Stumps me.....Error "java.lang.String cannot be cast to
>> java.util.UUID" at
>> 2. "custom type stops working" at
>> This is an attempt to merge them into one and find the cause.
>> I tried to reproduce the issue with Cayenne unit tests, but succeeded only
>> partially:
>> I was using Cayenne 3.2-SNAPSHOT (this is trunk and should be nearly
>> identical to 3.1B1). Reading and writing meaningful PK with custom type
>> works as excepted. The problem I found is in reading to-one relationship
>> pointing to a meaningful PK with custom type. But I could not reproduce a
>> ClassCastException.
>> Arturo, Kanwar, would it be possible to provide me with the full mapping
>> of a failing entity and all its relationships, and a piece of code that
>> leads to ClassCastException (via CAY-1728 Jira or directly via email if you
>> don't want to expose your project mapping) ? If you can build a small
>> standalone test (Junit or just main(..)) it will be extremely helpful.
>> Thanks,
>> Andrus

View raw message