openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dick (JIRA)" <>
Subject [jira] Created: (OPENJPA-510) ReverseMappingTool generates incorrect SQL for PostgreSQL if -fk = true
Date Wed, 06 Feb 2008 04:35:08 GMT
ReverseMappingTool generates incorrect SQL for PostgreSQL if -fk = true

                 Key: OPENJPA-510
             Project: OpenJPA
          Issue Type: Bug
          Components: jdbc
    Affects Versions: 1.1.0
         Environment: PostgreSQL
            Reporter: Michael Dick

Opening on behalf of Tim Holloway per email to the OpenJPA mailing list. 

Synopsis: Invalid code is generated when internally-generated foreign
key names are used and the ReverseMappingTool is run with the "-fk"
option set to true.

Description: If a constraint name is not explicitly defined, PostgreSQL
v7 synthesizes constraint names in the form "$n", where n is numeric,

                     Table "public.bus_stops"
     Column       |         Type          |       Modifiers
 stop_id           | integer               | not null
 street1_name      | character varying(32) | not null
 street1_qualifier | character varying(11) |
 street1_block     | integer               |
 street2_name      | character varying(32) |
 street2_qualifier | character varying(11) |
 street2_block     | integer               |
 longitude         | numeric(16,8)         | not null default 0.0
 latitude          | numeric(16,8)         | not null default 0.0
 elevation         | numeric(16,8)         | not null default 0.0
 description       | text                  |
 sheltered         | boolean               | not null default false
 inbound           | boolean               | not null
 street1_type      | character varying(8)  | not null
 street2_type      | character varying(8)  | not null
 street1_direction | character varying(5)  | not null
 street2_direction | character varying(5)  | not null
   "stop2_pkey" primary key, btree (stop_id)
Foreign-key constraints:
   "$1" FOREIGN KEY (street1_direction) REFERENCES
   "$2" FOREIGN KEY (street2_direction) REFERENCES
   "fk_bus_stops_street1_type" FOREIGN KEY (street1_type) REFERENCES
   "fk_bus_stops_street2_type" FOREIGN KEY (street2_type) REFERENCES

Consequences: Note the generated code for synthesized and explicit
constraint names:
 * Auto-generated by:
 * org.apache.openjpa.jdbc.meta.ReverseMappingTool
@Table(schema="public", name="bus_stops")
public class BusStops {
       @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.MERGE)
       @JoinColumn(name="street1_direction", nullable=false)
       private LkStreetDirections 1; //<==== WRONG

mappedBy="1", cascade=CascadeType.MERGE)
       private Set<TripStops> 1Inverses = new HashSet<TripStops>();

       @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.MERGE)
       @JoinColumn(name="street2_direction", nullable=false)
       private LkStreetDirections 2; //<==== WRONG

mappedBy="2", cascade=CascadeType.MERGE)
       private Set<RouteStops> 22Inverses = new HashSet<RouteStops>();

       @Column(columnDefinition="text", length=2147483647)
       private String description;

       private double elevation;

       @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.MERGE)
       @JoinColumn(name="street1_type", nullable=false)
       private LkStreetTypes fkBusStopsStreet1Type;  //<==== CORRECT

       @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.MERGE)
       @JoinColumn(name="street2_type", nullable=false)
       private LkStreetTypes fkBusStopsStreet2Type;  //<==== CORRECT

(remainder of code omitted as immaterial).

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message