File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate naming strategy problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate naming strategy problem" Watch "Hibernate naming strategy problem" New topic
Author

Hibernate naming strategy problem

ayan sevi
Greenhorn

Joined: Sep 21, 2006
Posts: 21
Hi, hibernate newbie here. I'm having problem with the use of naming strategy, wherein according to hibernate docs, it should generate a foreign key column name with the format "name of the relationship in the owner side, _ (underscore), and the name of the primary key column(s) in the owned side", i.e. entity_id. When naming strategy was not specified leaving hibernate to use DefaultNamingStrategy, it behaves correctly, but when I tried to specify the naming strategy, this time with ImprovedNamingStrategy, it generates wrong column name, i.e. expected was "entity_id", it only generates "entity".

I'm using Maven2 plugin hbm2ddl for generating the schema.

Hibernate version: hibernate-3.2.1.ga, hibernate-annotation-3.2.1.ga

The generated SQL (show_sql=true):

alter table gateway_type_test
drop constraint FKB0101E3CA31F223D;

drop table gateway_test;

drop table gateway_type_test;

create table gateway_test (
id int identity not null,
name varchar(255) not null,
description varchar(255) null,
ssl tinyint not null,
port int not null,
user_name varchar(255) null,
password varchar(255) null,
sms_api_id varchar(255) null,
primary key (id)
);

create table gateway_type_test (
id int identity not null,
name varchar(255) not null,
gateway int null,
primary key (id)
);


alter table gateway_type_test
add constraint FKB0101E3CA31F223D
foreign key (gateway)
references gateway_test;



Thanks.
ayan sevi
Greenhorn

Joined: Sep 21, 2006
Posts: 21
Anyone who has thoughts on this???
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

Show us your mapping and we will show you ours.

And maybe your NamingStrategy code.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Hibernate naming strategy problem
 
Threads others viewed
Foreign Key Constraint Fails
Hibernate exception in OneToOne mapping
ORM and Antipatterns
Ant build in Beginning Hibernate
Replacing *.hbm.xml files with @Annotations.
developer file tools