Community
Participate
Working Groups
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.
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
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.
I published a new build which should solve this (also escape names even if they are not truncated). gr. Martin