Community
Participate
Working Groups
Build Identifier: 1.1.2.v201011231049 After the update to Hibernate 3.6 certain indexes can not be created. (see model attached) I have the option "teneo.mapping.add_index_for_fk" set to "true". With hsqldb it seems to work, I'm using PostgreSQL 8.4. Here the Log messages I get: 16:40:49.546 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - alter table "addressdata_types" add column "addressdata_e_id" int8 not null 16:40:49.546 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create table "addressdata" (e_id int8 not null, dtype varchar(255) not null, e_version int4 not null, "address" varchar(500), "zip" varchar(255), "city" varchar(255), "code_country_id" varchar(255), "code_state_id" varchar(255), primary key (e_id)) 16:40:49.562 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - alter table "communicationdata_types" add column "communicationdata_e_id" int8 not null 16:40:49.562 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create table "communicationdata" (e_id int8 not null, dtype varchar(255) not null, e_version int4 not null, "basetype" varchar(255), "value" varchar(255), primary key (e_id)) 16:40:49.578 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - alter table "addressdata_types" add constraint FK2DA6FE98A76182D4 foreign key ("addressdata_e_id") references "addressdata" 16:40:49.578 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create index AddressData_types on "addressdata_types" ("addressdata_e_id", "code_id") 16:40:49.578 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create index AddressData_types on "addressdata_types" ("addressdata_e_id", "code_id") 16:40:49.578 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - FEHLER: Relation »addressdata_types« existiert bereits 16:40:49.578 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - alter table "addressdata" add constraint addressdata_state foreign key ("code_state_id") references "basiccode" 16:40:49.578 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - alter table "addressdata" add constraint addressdata_country foreign key ("code_country_id") references "basiccode" 16:40:49.593 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create index addressdatadtype on "addressdata" (dtype) 16:40:49.593 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create index AddressData_state on "addressdata" ("code_state_id") 16:40:49.593 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create index AddressData_state on "addressdata" ("code_state_id") 16:40:49.593 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - FEHLER: Relation »addressdata_state« existiert bereits 16:40:49.593 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create index AddressData_country on "addressdata" ("code_country_id") 16:40:49.593 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create index AddressData_country on "addressdata" ("code_country_id") 16:40:49.593 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - FEHLER: Relation »addressdata_country« existiert bereits 16:40:49.593 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - alter table "communicationdata_types" add constraint FKB21C3FFA9C1A9814 foreign key ("communicationdata_e_id") references "communicationdata" 16:40:49.593 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create index CommunicationData_types on "communicationdata_types" ("communicationdata_e_id", "code_id") 16:40:49.593 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create index CommunicationData_types on "communicationdata_types" ("communicationdata_e_id", "code_id") 16:40:49.593 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - FEHLER: Relation »communicationdata_types« existiert bereits 16:40:49.593 [main] DEBUG o.h.tool.hbm2ddl.SchemaUpdate - create index communicationdatadtype on "communicationdata" (dtype) 16:40:49.593 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - schema update complete Reproducible: Always
Created attachment 183678 [details] stripped model with fk relations
for the record, I'm using HbEntityDataStore
Hi Flavio, Afaics the error is this: 16:40:49.578 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create index AddressData_types on "addressdata_types" ("addressdata_e_id", "code_id") 16:40:49.578 [main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - FEHLER: Relation »addressdata_types« existiert bereits so it seems to fail because the index already exists. Does it indeed already exist? Or does it fail because it tries to create an index with the same name as the table? What index was created in the previous version of Hibernate? gr. Martin
Well the error occurs on a empty database as well as on a created one. There is a database table called "addressdata_types", I guess that is the problem. I just looked at an old database and there were no indexes at all, for none of the model tables??? I'm a bit confused, maybe that never worked for PostgreSQL. In my old MSSQL database the indexes exist. Is there a way to add a prefix/suffix to the index name? I haven't found an option. I'm using String UUIDs for the Ids, could that be a problem? greets Flavio
There is an option to set a prefix for foreign key names: PersistenceOptions.SQL_FOREIGN_KEY_NAME_PREFIX it's current value is a space. Can you try and see what happens? gr. Martin
Sorry, I mean the default value of the option is an empty string ofcourse
I tried the option "teneo.naming.sql_fk_name_prefix" with value "fk_". There still is the table "addressdata_types". Now the one constraint of it is called "fk_addressdata_types". If I disable "teneo.naming.set_foreign_key_name" option I get "fk2da6fe98384382ba" prefix is ignored. But I still get the error message.
Here the stacktrace I get: org.postgresql.util.PSQLException: FEHLER: Relation »addressdata_types« existiert bereits at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1343) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:194) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:282) at org.enhydra.jdbc.core.CoreStatement.executeUpdate(CoreStatement.java:117) at org.tranql.connector.jdbc.StatementHandle.executeUpdate(StatementHandle.java:166) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:204) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:373) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902) at org.eclipse.emf.teneo.hibernate.HbEntityDataStore.buildEntityManagerFactory(HbEntityDataStore.java:251) at org.eclipse.emf.teneo.hibernate.HbEntityDataStore.initialize(HbEntityDataStore.java:116) at com.softmodeler.server.persistence.SoftmodelerHbEntityDataStore.initialize(SoftmodelerHbEntityDataStore.java:69)
Hi Flavio, You still get the error message when you set the prefix to fk_? Can you check the hbm to see if the prefix is ignored somehow? Your last exception seems to be related to that Hibernate tries to create the table an extra time, or is the error message related to the fk in your opinion? gr. Martin
I get the exact same exception with or without the prefix. I don't get the exception if I disable "teneo.mapping.add_index_for_fk". I haven't checked the hbm but the table's ("addressdata_types") constraint is called "fk_addressdata_types" with the prefix, fk2da6fe98384382ba otherwise. Does the prefix relate to the index? Locking at the earlier log messages I noticed: create index AddressData_types on "addressdata_types" ("addressdata_e_id", "code_id") So Hibernate is trying to create an index which has the same name as the table and PostgreSQL does not like that. Is there a way to manipulate index creation? Have not found anything in the PersistenceOptions.
Hi Flavio, I published a new build a few mins back which has a new option to set an index prefix. I have not tested it, so I hope it works... If you have time, can you try? It is this option: PersistenceOptions.SQL_INDEX_KEY_NAME_PREFIX The default value is an empty string. gr. Martin
You're the best! It works. Maybe you should think about having a default prefix (maybe "idx_"), so others with PostgreSQL don't run into this? greets and thanks Flavio
I updated the docs also. Because of backward compatibility I prefer not to change the default setting of this option right away. I added a separate remark about this in the docs though, so hopefully that helps: http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Options#General_Options gr. Martin