Community
Participate
Working Groups
Build Identifier: 20110218-0911 It seems that if the default value on an EChar attribute is not set, or if it is set to '\u0000' that CDO cannot persist the object due to an "invalid byte sequence for encoding 'UTF8': 0x00" error. This may be specific to only a PostgreSQL datastore, but I am unable to test with other datastore implementations at this time. Details of this bug have been discussed in the forums: http://www.eclipse.org/forums/index.php/t/215023/ Reproducible: Always Steps to Reproduce: 1. Configure PostgreSQL as the CDO datastore 2. Generate an ECore model with an object consisting of an EChar attribute. Do not set its default attribute. 3. Instantiate the object with the EChar attribute, but do not change the EChar attribute's value. 4. Commit the object via CDO.
Created attachment 198465 [details] Original exception and stack trace
The explanation seems to be easy: Since the attribute is not unsettable, its default value is zero (0), because EChar reflects a base type (char). Since the default type mapping represents a EChar or ECharacter as a String of length 1, it writes this string to the database. PostgreSQL, however does not support NUL-characters in Strings: (e.g., see http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00106.php) The solution is more difficult. In my opinion, the easiest way is to introduce a new type mapping, which maps EChar (and ECharacter) to a number field (instead a string field). I don't want to change the behavior of the existing type mapping, because of backwards-compatibility and because the string-representation is more 'direct'. I'll have a look if the new TypeMapping can be configured transparently. (If not, a model annotation to use the correct type mapping would be needed).
Created attachment 198599 [details] patch-v1 I have created a test case and a patch. Introducing a char to integer mapping and setting the database type for char to integer for PostgreSQL fixes the problem. See attached patch. Eike, please review.
Created attachment 199160 [details] Patch v2 Adjusted manifest version to 4.0.100. Note that I'm going to move this bug/fix to 4.1!!!
More info here: http://stackoverflow.com/questions/1347646/postgres-error-on-insert-error-invalid-byte-sequence-for-encoding-utf8-0x0
Guys, can we commit this fix? Fixes the issue nicely.
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Nothing in this patch applies to master anymore. Please reopen this bug if you feel a need.
I managed to merge this old bug with master. Reopening for fixation
I've provided a ColumnTypeModifier concept in bug 408479.
I've taken the new EChar -> DBType.INTEGER type mappings and added a ColumnTypeModifier for Postgres. The attached test passes adn is committed: commit aa8bfe023cad0c187cc2d88518456b1e8abf7828
Available in R20130613-1157 (4.2)