| Summary: | [DB] [PostgreSQL] Exception when persisting EChar attribute with default '\u0000' value | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Modeling] EMF | Reporter: | Josh M <public.web.josh> | ||||||||
| Component: | cdo.db | Assignee: | Eike Stepper <stepper> | ||||||||
| Status: | CLOSED FIXED | QA Contact: | Eike Stepper <stepper> | ||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | public.web.josh, stefan, stepper | ||||||||
| Version: | 4.2 | Flags: | stepper:
review+
|
||||||||
| Target Milestone: | --- | ||||||||||
| Hardware: | All | ||||||||||
| OS: | All | ||||||||||
| Whiteboard: | |||||||||||
| Bug Depends on: | 323006, 408479 | ||||||||||
| Bug Blocks: | |||||||||||
| Attachments: |
|
||||||||||
|
Description
Josh M
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) |