Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: hbm2ddl creates FK names that are too long
PostPosted: Wed Nov 26, 2008 7:53 am 
Newbie

Joined: Thu Apr 19, 2007 7:22 am
Posts: 2
When hbm2dll creates FK constraint names, it does so without following database resrictions. As hbm2dll knows it is using the Oracle10gDialect then it should not attempt to create FK constraint names that have more than 30 characters. With union-subclass mapping the pattern used by hbm2dll is to give a FK constraint an 18 character name on the class that directly has the association requiring the FK. If that class is subclassed the FK constraint added to the tables of the subclasses has 18+8n characters. Where n is the level of subclassing. Only two levels of subclassing are required before the constraint name exceeds 30 characters as below.

I know it is possible to configure the initial name used for constraints using the foreign-key attribute in the mapping. However if I set that to 1 character then I still have a problem when 1 + 4*8 = 33. Therefore even using the foreign-key attribute I can only get 3 levels of subclassing.

Shouldn't the algorithm to create FK names be aware of the 30 character limit, i.e be dialect aware. Couldn't it simply create a hashcode of the hashcode it currently creates and limit it to 30 characters (including the 'FK').

In the example below constraints of the lengths shown get added to each table for the many-to-one mapping with name="requestedNE":

Class
IACEndpointConfigElement (FK4C10C05A145A4B50) 18 chars
IInterfaceConfigElement (FK4C10C05A145A4B50b6728c4a) 18 + 8 = 26 chars
IFRvcConfigElement (FK4C10C05A145A4B50b6728c4ace4cc838) 18 + 8 + 8 = 34 chars ERROR


Hibernate version:
3.2.2
Mapping documents:

<class name="productSpecific.advancedAppInterfaces.attachmentCircuitService.IACEndpointConfigElement" table="IACEndpointConfigElement" abstract="true">

<many-to-one name="requestedNE"
class="productSpecific.advancedAppInterfaces.attachmentCircuitService.IACServiceNEAssignmentConfigElement"
column="requestedNE_ID"
foreign-key="none"
not-found="ignore"
/>
<union-subclass name="productSpecific.advancedAppInterfaces.attachmentCircuitService.IInterfaceConfigElement" table="IInterfaceConfigElement" abstract="false">
<union-subclass name="productSpecific.advancedAppInterfaces.attachmentCircuitService.IFRvcConfigElement" table="IFRvcConfigElement" abstract="false">
</union-subclass>
</union-subclass>
</class

Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):

[hibernatetool] 2008-11-26 09:56:40,000 DEBUG SchemaExport:303 -
[hibernatetool] create table developer.IFRvcConfigElement (
[hibernatetool] INSTANCEID number(19,0) not null,
[hibernatetool] oid varchar2(2048 char) not null,
[hibernatetool] ReferenceKey varchar2(2048 char),
[hibernatetool] InstanceName varchar2(255 char),
[hibernatetool] InstanceDescription varchar2(255 char),
[hibernatetool] requestedNE_ID number(19,0),
[hibernatetool] ProtocolIFType number(10,0),
[hibernatetool] InterfaceEncapType number(10,0),
[hibernatetool] Dlci number(10,0),
[hibernatetool] primary key (INSTANCEID)
[hibernatetool] );

[hibernatetool] alter table developer.IFRvcConfigElement
[hibernatetool] add constraint FK4C10C05A145A4B50b6728c4ace4cc838
[hibernatetool] foreign key (requestedNE_ID)
[hibernatetool] references developer.IACSrvcNEAssgnmntCnfgElmnt;
[hibernatetool] 2008-11-26 10:00:18,515 ERROR SchemaExport:274 - Unsuccessful: alter table developer.IFRvcConfigElement add constraint FK4C10C05A145A4B50b6728c4ace4cc838 foreign key (requestedNE_ID) references developer.IACSrvcNEAssgnmntCnfgElmnt
[hibernatetool] 2008-11-26 10:00:18,515 ERROR SchemaExport:275 - ORA-00972: identifier is too long

Debug level Hibernate log excerpt:
DEBUG

Problems with Session and transaction handling?
N/A


Top
 Profile  
 
 Post subject: Long identifier names not acceptable to Oracle
PostPosted: Wed Nov 26, 2008 8:40 am 
Newbie

Joined: Wed Nov 26, 2008 8:31 am
Posts: 1
I believe that there is a serious need to address the problem described above. In my work I am using Hibernate to map a highly complex object model to an Oracle RDB. We quickly ran into the situation where we can not specify object inheritance hierarchies deeper than 3 (in the default case) or 5 (using the trick described above) and still enforce referential integrity. The foreign key constraints can not be created due to the long name generated by Hibernate. This has caused us much pain and we have not been able to come up with a reasonable solution.

I'm eagerly waiting for a near future enhancement to Hibernate that would address above problem.

Thanx much,
*Yoram


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Tue Nov 24, 2009 11:11 am 
Newbie

Joined: Tue Feb 06, 2007 11:59 am
Posts: 4
You can anyway specify manually the foreign key name but a fix for this whould be greately appreciated.


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Sun Dec 13, 2009 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
provide a patch or provide foreignkey names explicitly (which is a good practice anyway)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Wed Apr 28, 2010 8:23 am 
Newbie

Joined: Fri Apr 09, 2010 5:49 am
Posts: 10
is this issue still open? I'm getting the same errors using hibernate 3.4 over Ingres database 9.3 community edition.


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Fri Jan 21, 2011 2:05 pm 
Newbie

Joined: Fri Jan 21, 2011 1:45 pm
Posts: 1
This issue is actually badly named. The problem described in the original post is that the foreign key constraint name is too long, not the foreign key column name. The foreign key column name length can be controlled using the pluggable naming strategy or by explicitly setting the foreign key name using annotations. The foreign key constraint however is not configurable as far as I can see (beyond specifying the prefix, as described by the original poster). It certainly does not appear on the org.hibernate.cfg.NamingStrategy interface, unless I am missing something.

So, the replies suggesting "provide foreignkey names explicitly" or "You can anyway specify manually the foreign key" do not address this bug unfortunately.

... Which is a long way of saying that this is a real bug in Hibernate and I vote for a fix! It's currently causing me a problem too, precisely as described in the original post.

(Hibernate version 3.0.5.RELEASE, Oracle 11)

P.S. I think the whole problem of Hibernate generated identifiers being too long for Oracle "out of the box" needs fixing - there is really no need at all for constraint names or index names to be more than 30 characters to achieve uniqueness. I am happy to look for a solution, even submit a patch, so I'm not just telling other people to do some work for me ;-), however as I am relatively new to Hibernate, someone with years on the project might be better suited.


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Fri Jan 21, 2011 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
hibernate is on git now, make a pull request - it's not as trivial as you think ;)

its easy to make things unique - but you also need it to be deterministic across clusters and what not...

/max

philip.j.r.jones wrote:
This issue is actually badly named. The problem described in the original post is that the foreign key constraint name is too long, not the foreign key column name. The foreign key column name length can be controlled using the pluggable naming strategy or by explicitly setting the foreign key name using annotations. The foreign key constraint however is not configurable as far as I can see (beyond specifying the prefix, as described by the original poster). It certainly does not appear on the org.hibernate.cfg.NamingStrategy interface, unless I am missing something.

So, the replies suggesting "provide foreignkey names explicitly" or "You can anyway specify manually the foreign key" do not address this bug unfortunately.

... Which is a long way of saying that this is a real bug in Hibernate and I vote for a fix! It's currently causing me a problem too, precisely as described in the original post.

(Hibernate version 3.0.5.RELEASE, Oracle 11)

P.S. I think the whole problem of Hibernate generated identifiers being too long for Oracle "out of the box" needs fixing - there is really no need at all for constraint names or index names to be more than 30 characters to achieve uniqueness. I am happy to look for a solution, even submit a patch, so I'm not just telling other people to do some work for me ;-), however as I am relatively new to Hibernate, someone with years on the project might be better suited.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Wed Apr 04, 2012 4:33 am 
Newbie

Joined: Wed Apr 04, 2012 4:23 am
Posts: 1
Anyone can tell me is it fixed?
BTW: It has been 4 years since this issue reported LOL.
It is currently causing me to dance around our project cause the constraint names generated by the hibernate (honestly, I don't even completely understand this process & how are they being generated) are too long for the Oracle database.
I also want to add that it is a shame for the Oracle. 30 symbols? Really? &No longer? I feel like in 18th century. @_@
I wonder is there a way to change it & make the Oracle database server to allow long table names & constraint names || idk???
Or do the hibernate developers think that I should just throw away my Oracle database server and switch to Open Source Software or just shoot myself %_%

PS: Can anyone please point out just any solution for this problem, even not too elegant

_________________
Sorry for my bad English


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Wed Apr 04, 2012 6:57 am 
Newbie

Joined: Fri Apr 09, 2010 5:49 am
Posts: 10
you can do a workaround like:

@OneToMany(mappedBy="associatedTCAParameterProfile",
cascade=CascadeType.ALL,
targetEntity=DBTpImpl.class)
@ForeignKey(name="tcapp2tp")
private List<DBTp> associatedTpList = new ArrayList<DBTp>();


Top
 Profile  
 
 Post subject: Re: hbm2ddl creates FK names that are too long
PostPosted: Fri Jul 13, 2012 5:01 pm 
Newbie

Joined: Fri Nov 06, 2009 6:05 am
Posts: 10
max wrote:
hibernate is on git now, make a pull request - it's not as trivial as you think ;)

its easy to make things unique - but you also need it to be deterministic across clusters and what not...


Would you care to elaborate on this "not as trivial as you think" piece? Why would a generated value have to be deterministic?

Marcel

Side note: there has been a bug report for this against Hibernate 3.0 back in 2005. It was closed simply because there was no test case attached...that's another way to deny problems that exist.

_________________
my2cents @ http://www.frightanic.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.