Apparently @Enumerated annotation does not apply to an array of enum values. 
When I take it away as shown below,

    @Column(nullable=false)
    @Basic( fetch = FetchType.EAGER )
    //@Enumerated( EnumType.STRING )
    private Measure[] measures;

I am able to persist the entity. Query also returns a correct array of enum 
values. According to the documentation, the @Enumerated annotation controls how 
the field maps to the database, i.e., String or Ordinal. For array and 
collection, the field is mapped to Blob in the database. 
  
-f

--- On Wed, 6/4/08, JimOR <[EMAIL PROTECTED]> wrote:

> From: JimOR <[EMAIL PROTECTED]>
> Subject: Problem Querying Entity With Field Declared as an Enum Array
> To: [email protected]
> Date: Wednesday, June 4, 2008, 1:35 PM
> I have an Entity class that contains a persisted field which
> is an array of
> enum.  Whenever I attempt to query this entity, I receive
> an
> org.apache.openjpa.persistence.ArgumentException, which
> seems to indicate
> that we're trying to find a values() method on the
> array type.  Tests with
> the field configured as a singleton work beautifully.
> 
> My use case is to provide persistence of ad-hoc report
> formats containing
> columns selected from a fixed list, and I'd prefer to
> have a single table
> row for each saved report in the db.
> 
> I'm wondering if I'm treading in unsupported
> ground, or am I missing
> something in my enum/entity declaration.
> 
> I'm using OpenJPA 1.01 (embedded from OpenEJB 3.0) on
> WinXP/Java 1.5.0_14
> with PostgreSQL 8.3.1
> 
> The entire stack trace is 
> http://www.nabble.com/file/p17656042/stacktrace
> here , but the following lines look like the culprit:
> Caused by: <openjpa-1.0.1-r420667:592145 fatal user
> error>
> org.apache.openjpa.persistence.ArgumentException: null
> at
> org.apache.openjpa.jdbc.meta.strats.EnumValueHandler.map(EnumValueHandler.java:63)
> 
> and:
> Caused by: java.lang.NoSuchMethodException:
> [Lportfolio.data.entities.enums.Measure;.values()
>       at java.lang.Class.getMethod(Class.java:1581)
>       at
> org.apache.openjpa.jdbc.meta.strats.EnumValueHandler.map(EnumValueHandler.java:60)
> 
> My entity defines the field as:
>       @Column(nullable=false)
>       @Basic( fetch = FetchType.EAGER ) 
>       @Enumerated( EnumType.STRING ) 
>       private Measure[] measures; 
>       public Measure[] getMeasures() {
>               return measures;
>       }
>       public void setMeasures(Measure[] measures) {
>               this.measures = measures;
>       }
> and my enum declaration in part contains:
> public enum Measure {
>       ReInv ("Re-Invested", false),
>       Invest ("Invested", false),
>       Cost ("Cost", false),
>       Value ("Value", false),
>       AvgCost ("Avg Cost", true),
>       
>       private String description;
>       private boolean perShare;
>       private Measure(String desc, boolean per){
>               this.description=desc;
>               this.perShare=per;
>       }
>       public String desc(){return this.description;}
>       public boolean pershare(){return this.perShare;}
> }
> 
> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Problem-Querying-Entity-With-Field-Declared-as-an-Enum-Array-tp17656042p17656042.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


      

Reply via email to