-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Generate table creation ddl with primary key as constraint?
PostPosted: Thu Jan 10, 2008 9:24 am 
Newbie

Joined: Fri Jul 27, 2007 4:24 am
Posts: 1
Hibernate version:
3.2.5GA
Mapping documents:
not relevant
Code between sessionFactory.openSession() and session.close():
not relevant
Full stack trace of any exception that occurs:
not relevant
Name and version of the database you are using:
DB2 8.3.2
The generated SQL (show_sql=true):
not relevant
Debug level Hibernate log excerpt:
not relevant

Hello there!

I want to customize the table creation script which is generated by the hibernate tool, namely:

instead of

Code:
create table customer (id bigint generated by default as identity, name varchar(255), primary key (id));

I would love to get this splitted to the two expressions:

Code:
create table customer (id bigint generated by default as identity, name varchar(255));
alter table customer add constraint pcustomer primary key (id);

The reason for that is that in the latter case I can specify the soundable name of the PK-constraint.

After a short investigation I have found that currently it is not possible to do it this way because it is not enough just to write a custom implementation of the Dialect, but it is also necessary to subclass a Table due to the fact that the generation of a primary key is happened directly in the Table class. Or maybe I have to subclass Configuration? But how coud I use subclassed Configuration in hibernate?

The second problem is that currenty there is no way to define a name for a primary key constrain at all (but using a reasonable naming convention I still could generate a suitable PK name automatically).

Is my understanding of that problem correct?
Is there any other solution to this task?

Regards,
TCh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 7:20 am 
Newbie

Joined: Tue Feb 19, 2008 7:05 am
Posts: 1
At present you can define the constraint name by using the columnDefinition attribute @column.

For ex. you can define like this
@column(columnDefinition="number(19,0) constraint PK_TABLE_ID primary key (id)")
private Long id;

I also looking for some solution to define constraints for all types, not only for Primary Keys also for Unique constraints.

It will be always good if we have some kind of annotaion configuration in the class itself like the @ForeignKey where we can define the foreign key name.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.