openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: Java enum column incompatibility warning
Date Fri, 23 May 2014 18:29:37 GMT
Interesting.  Can you provide your MimeType.java?  Thanks!


On Fri, May 23, 2014 at 11:51 AM, Jason Reilly <jdr0887@renci.org> wrote:

> Changing *just* the openjpa dependency version to 2.2.2 in my pom, the
> schema creation looks like this:
>
> CREATE TABLE file_data (file_data_id BIGINT NOT NULL, date_created
> TIMESTAMP, md5 VARCHAR(255), mime_type VARCHAR(255), name VARCHAR(255),
> path VARCHAR(32672), PRIMARY KEY (file_data_id));
>
>
> Regards,
> Jason
>
>
> On 05/23/2014 10:49 AM, Kevin Sutter wrote:
>
>> Hi Jason,
>> Something's out of whack...  I went to the code that determines the size
>> to
>> use for enum fields and it has used the largest enum string length since
>> 2006...  We have never defaulted to 255 for @Enumerated types, for any
>> database...
>>
>> The DDL you posted was for 2.3.0.  Any chance you still have your 2.2.x
>> environment and you can capture the ddl for that run?
>>
>> The code is quite simple if you are interested.  Here links for the 2.2.x
>> branch as well as 2.3.0.  The code that is doing this length determination
>> is like this:
>>
>>          if (_ordinal)
>>              col.setJavaType(JavaTypes.SHORT);
>>          else {
>>              // look for the longest enum value name; use 20 as min
>> length to
>>              // leave room for future long names
>>              int len = 20;
>>              for (int i = 0; i < _vals.length; i++)
>>                  len = Math.max(_vals[i].name().length(), len);
>>
>>              col.setJavaType(JavaTypes.STRING);
>>              col.setSize(len);
>>          }
>>
>> [1]
>> https://svn.apache.org/repos/asf/openjpa/branches/2.2.x/
>> openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/
>> strats/EnumValueHandler.java
>> [2]
>> https://svn.apache.org/repos/asf/openjpa/tags/2.3.0/
>> openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/
>> strats/EnumValueHandler.java
>>
>>
>> On Fri, May 23, 2014 at 8:17 AM, Jason Reilly <jdr0887@renci.org> wrote:
>>
>>  Sure....
>>>
>>>
>>> Here is the log statement:
>>>
>>> 2014-05-22 14:26:44,437 | WARN  | Thread-128       | Schema
>>>              | b.log.SLF4JLogFactory$LogAdapter  103 | 156 -
>>> org.apache.openjpa - 2.3.0 | Existing column "mime_type" on table
>>> "public.file_data" is incompatible with the same column in the given
>>> schema
>>> definition. Existing column:
>>>
>>> Full Name: file_data.mime_type
>>>
>>> Type: varchar
>>>
>>> Size: 255
>>>
>>> Default: null
>>>
>>> Not Null: false
>>>
>>> Given column:
>>>
>>> Full Name: file_data.mime_type
>>>
>>> Type: varchar
>>>
>>> Size: 30
>>>
>>> Default: null
>>>
>>> Not Null: false
>>>
>>>
>>>
>>> And here is the column declaration in my model for FileData.mimeType:
>>>
>>>      @Column(name = "mime_type")
>>>
>>>      @Enumerated(EnumType.STRING)
>>>
>>>      private MimeType mimeType;
>>>
>>>
>>>
>>> And from the schema creation script:
>>>
>>> CREATE TABLE file_data (file_data_id BIGINT NOT NULL, date_created
>>> TIMESTAMP, md5 VARCHAR(255), mime_type VARCHAR(30), name VARCHAR(255),
>>> path
>>> VARCHAR(32672), PRIMARY KEY (file_data_id));
>>>
>>>
>>> The longest value in the MimeType enum is 30 characters in length.
>>> Observing some of the other warning messages, it seems that if the Enum
>>> value length is less than 20, the expected column length is 20.  So, 20
>>> is
>>> the lower bounds.
>>>
>>> Regards,
>>> Jason
>>>
>>>
>>> On 05/22/2014 05:01 PM, Kevin Sutter wrote:
>>>
>>>  Hi Jason,
>>>> I'm not aware of a change that went into 2.3.0 that would affect this
>>>> type
>>>> of processing.  I just searched the JIRAs as well and didn't find
>>>> anything...  Can you post the exact warning message you are receiving?
>>>> Along with your Entity definition of the Enumerated type?  And, extract
>>>> the
>>>> schema definition from your database?  I know we've had some issues with
>>>> sequence generators and Postgres, but I'm not aware of any issues with
>>>> the
>>>> processing of enums.
>>>>
>>>> Thanks, Kevin
>>>>
>>>>
>>>> On Thu, May 22, 2014 at 3:30 PM, Jason Reilly <jdr0887@renci.org>
>>>> wrote:
>>>>
>>>>   With OpenJPA 2.2.2, the generated column length for an
>>>>
>>>>> @Enumerated(EnumType.STRING) is varchar(255) in Postgresql.  With an
>>>>> upgrade to OpenJPA 2.3.0, I think that the expected column length is
>>>>> the
>>>>> length of the Enum's longest value....usually shorter than 255
>>>>> characters.
>>>>>    I suspect this could problematic (at least annoying) if the database
>>>>> schema was first created with OpenJPA 2.3.0 and the database column
>>>>> length
>>>>> had to be adjusted every time I add a new Enum that is longer than the
>>>>> previously longest Enum value.
>>>>>
>>>>>
>>>>> On 05/22/2014 04:09 PM, Kevin Sutter wrote:
>>>>>
>>>>>   Well, if you don't have access or the means to update this varchar
>>>>>
>>>>>> length,
>>>>>> then you probably have to ignore it...  :-)  This is a warning to
>>>>>> indicate
>>>>>> a mismatch.  I suppose you can ignore it, but then you have a chance
>>>>>> of
>>>>>> truncated values.  Are the enum values pre-defined like the column
>>>>>> size?
>>>>>> Or, can you maybe abbreviate the enum values to make them fit the
>>>>>> column
>>>>>> size?  It's really up to you whether these warnings are safe to ignore
>>>>>> or
>>>>>> not.
>>>>>>
>>>>>> Kevin
>>>>>>
>>>>>>
>>>>>> On Thu, May 22, 2014 at 2:10 PM, Jason Reilly <jdr0887@renci.org>
>>>>>> wrote:
>>>>>>
>>>>>>    Sorry....I am using OpenJPA 2.3.0
>>>>>>
>>>>>>  On 05/22/2014 03:09 PM, Jason Reilly wrote:
>>>>>>>
>>>>>>>    Hi all,
>>>>>>>
>>>>>>>  I am getting a warning that the column that an Enum is mapped
to
>>>>>>>> (as a
>>>>>>>> string) is incompatible with the column in the schema definition.
>>>>>>>> Looks
>>>>>>>> like the expected column size is the length of the longest
Enum
>>>>>>>> value.
>>>>>>>>    As
>>>>>>>> it is a warning and I don't easily have access to change
the varchar
>>>>>>>> length, can this be safely ignored?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Jason
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message