Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to query properties of an @Entity attribute mapped using EclipseLink @ReadTransformer and @WriteTransformer?
    primarykey
    data
    text
    <p>I am using EclipseLink 2.4.2.</p> <p>I have an @Entity with an attribute of type Money, which is a final class from an external library. Instances of Money are immutable and must be persisted as two columns, one for amount and one for currency.</p> <p>I am using a @ReadTransformer and two @WriteTransformers to do this:</p> <pre><code>@Transformation(fetch = FetchType.EAGER, optional = false) @ReadTransformer(transformerClass = MoneyReadTransformer.class) @WriteTransformers({ @WriteTransformer( transformerClass = MoneyCurrencyWriteTransformer.class, column = @Column(name = "SAVINGS_CURRENCY", nullable = false)), @WriteTransformer( transformerClass = MoneyAmountWriteTransformer.class, column = @Column(name = "SAVINGS_BALANCE", nullable = false)) }) private Money savings; </code></pre> <p>This works well; I can load and save the entity with no problem.</p> <p>The problem comes when I try to perform a JPQL query for entities based on attributes of the embedded Money instance:</p> <pre><code>SELECT t FROM Thing t WHERE t.savings.amount &gt; 0; </code></pre> <p>This returns:</p> <pre><code>org.eclipse.persistence.exceptions.JPQLException: Exception Description: Problem compiling [SELECT t FROM Thing t WHERE t.savings.amount &gt; 0]. [29, 45] The state field path 't.savings.amount' cannot be resolved to a valid type. </code></pre> <p>This kind of thing worked in Hibernate just fine (with UserTypes and a @Type annotation).</p> <p>I also noted the following messages on startup:</p> <pre><code>[EL Config]: metadata: 2013-04-28 15:30:04.276--Thread(Thread[main,5,main])--The default table generator could not locate or convert a java type (null) into a database type for database field (THING.SAVINGS_CURRENCY). The generator uses java.lang.String as default java type for the field. [EL Config]: metadata: 2013-04-28 15:30:04.276--Thread(Thread[main,5,main])--The default table generator could not locate or convert a java type (null) into a database type for database field (THING.SAVINGS_BALANCE). The generator uses java.lang.String as default java type for the field. </code></pre> <p>These messages go away if I define a columnDefinition on the @Column attribute for each @WriteTransformer. </p> <p>What might the problem be? My suspicion is that something's not right with the transformers, maybe I'm not setting a type hint somewhere - but it's non-obvious and examples are few and far between.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload