Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337580 - Option to NOT apply the name strategy to names specified explicitly via JPA annotations
Summary: Option to NOT apply the name strategy to names specified explicitly via JPA a...
Status: RESOLVED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Teneo (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Martin Taal CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-18 10:53 EST by Nikita CLA
Modified: 2011-04-26 15:38 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita CLA 2011-02-18 10:53:39 EST
Build Identifier: org.eclipse.emf.teneo-1.1.2-v201007191154

Currently, the name strategy (TeneoSQLNameStrategy by default) is applied to auto-generated table/column names, as well as names that are provided explicitly via @Table and @Column JPA annotations. Having the name strategy be executed on explicitly given names is problematic in a few cases:
 1. For auto-generated table/column names, it's useful to use the option "teneo.naming.strategy=lowercase" to have consistent casing. However, enabling this makes it impossible to map to existing tables that use different casing (on a case-sensitive database such as Oracle), because the names given in @Table and @Column annotations will also be run through the casing strategy.
 2. For auto-generated table/column names, it's useful to use the option "teneo.naming.max_sql_name_length" to limit the length of auto-generated column names. However, this makes it impossible to map to pre-existing tables with longer names, because the names given in @Table and @Column annotations will also be truncated (see http://www.eclipse.org/forums/index.php?t=msg&th=199575).

In order to support mapping to existing tables, but also use clean naming for auto-generated tables, it would be very useful to have an option to NOT apply the name strategy to explicit names. With the option enabled, auto-generated names would still use the strategy, but names provided via JPA annotations would be used as-is. Another alternative is if the name strategy could receive a parameter telling it whether the name was generated or provided explicitly. Finally another option would be to have two separate configurations, one for the name strategy for generated names, and one for the name strategy for explicit names.

Reproducible: Always

Steps to Reproduce:
1. Using a case-sensitive database (MySQL on Linux, or Oracle, or MS SQL Server with an appropriate collation set, such as "Latin1_General_BIN"), create a table with an upper-case name and upper-case column names.
2. Try to map a datatype to that table using explicit @Table and @Column JPA annotations with upper-case names.
3. Run hibernate hbm2ddl validation. This will fail because the name strategy by default uses lower-case and applies this even if the names are given explicitly in annotations.
Comment 1 Martin Taal CLA 2011-02-21 02:04:30 EST
The latest build of Teneo contains a new option:
teneo.naming.auto_adapt_manual_set_sql_names

the default is true (for backward compatibility). In your case you want to set this to false.

Can you test if it works for you?

gr. Martin
Comment 2 Nikita CLA 2011-04-25 10:01:20 EDT
I ran into an issue with the DDL generated for some types whose column names are reserved keywords. For this XSD:

  <xsd:complexType name="Attributes">
    <xsd:attribute name="string" type="xsd:string">
      <xsd:annotation>
        <xsd:appinfo source="appian.jpa">@Column(nullable="true")
        </xsd:appinfo>
      </xsd:annotation>
    </xsd:attribute>
    <xsd:attribute name="integer" type="xsd:integer">
      <xsd:annotation>
        <xsd:appinfo source="appian.jpa">@Column(nullable="true")
        </xsd:appinfo>
      </xsd:annotation>
    </xsd:attribute>
  </xsd:complexType>

  <xsd:complexType name="RecordWithListOfRecordsWithAttributes">
    <xsd:sequence>
      <xsd:element name="recordList" type="Attributes"
        minOccurs="0" maxOccurs="unbounded">
        <xsd:annotation>
          <xsd:appinfo source="appian.jpa">@Column(nullable="true")
          </xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

The DDL generated using AUTO_ADAPT_MANUAL_SET_SQL_NAMES=true looks like this (note the quoting of the "integer" and "string" cols):

create table `attributes` (
  a_id bigint not null auto_increment,
  `integer` decimal(19,2),
  `string` varchar(255),
  `rcrdwthlstfrcrdsw_rcrdlst_d` bigint,
  `rcrdwthlstfrcrds_rcrdlst_dx` integer,
  primary key (a_id)) ENGINE=InnoDB

The DDL generated using AUTO_ADAPT_MANUAL_SET_SQL_NAMES=false looks as follows (the "integer" and "string" cols are not quoted):

create table `attributes` (
  a_id bigint not null auto_increment,
  integer decimal(19,2),
  string varchar(255),
  `rcrdwthlstfrcrdsw_rcrdlst_d` bigint,
  `rcrdwthlstfrcrds_rcrdlst_dx` integer,
  primary key (a_id)) ENGINE=InnoDB

  [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table `attributes` (a_id bigint not null auto_increment, integer decimal(19,2), string varchar(255), `rcrdwthlstfrcrdsw_rcrdlst_d` bigint, `rcrdwthlstfrcrds_rcrdlst_dx` integer, primary key (a_id)) ENGINE=InnoDB
  [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'integer decimal(19,2), string varchar(255), `rcrdwthlstfrcrdsw_rcrdlst_d` bigint' at line 1

It looks like with this option set to false, column names don't get quoted, which causes a database error when the name happens to be a reserved keyword. The fields are actually not specifying the name explicitly; they are only using the @Column annotation to set the nullability.
Comment 3 Martin Taal CLA 2011-04-26 15:38:34 EDT
I published a new build which should solve this (also escape names even if they are not truncated).

gr. Martin