-->
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.  [ 3 posts ] 
Author Message
 Post subject: EJB3 naming strategy with quoted identifiers
PostPosted: Sat Oct 21, 2006 5:46 am 
Newbie

Joined: Thu Jun 22, 2006 6:35 am
Posts: 5
Hello,

My team and I are using v3.2.0.GA of Hibernate and Hibernate Annotations to persist the following classes:
Code:
@Entity
@Table(name = "`User`")
public class User implements Serializable {

   @Id @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;

   @ManyToMany
   private Set<Role> roles = new HashSet<Role>();

   ...
}

Code:
@Entity
@Table(name = "`Role`")
public class Role implements Serializable {

   @Id @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;

   ...
}


Since "User" and "Role" are SQL keywords, we intended to use backticks to quote these identifiers according to chapter 5.4 of the Hibernate Reference Documentation.

Unfortunately, the SQL statements generated by Hibernate look like that (in this case for the HSQLDB dialect but that should not matter):
Code:
SchemaExport:303 - create table "Role" (id bigint generated by default as identity (start with 1), ... primary key (id))
SchemaExport:303 - create table "User" (id bigint generated by default as identity (start with 1), ... primary key (id))
SchemaExport:303 - create table "User`_`Role" ("User`_i" bigint not null, role_id bigint not null, primary key ("User`_i", role_id))

The problem are the SQL statements for the association table. The default table/column names generated by the EJB3 naming strategy contain backticks and get truncated (e.g. "User`_i" instead of "User_id").

We tried EJB3NamingStrategy and DefaultComponentSafeNamingStrategy but in both cases the default generation of table/column names seems to struggle with quoted identifiers. I found a related issue at http://opensource.atlassian.com/projects/hibernate/browse/ANN-362 but that seems to have had another cause.

I am not quite familiar with the details of JPA but a key concept of the new specification was to provide sensible default values to ease the O/R-mapping. Even if quoted identifiers using backticks are not JPA conform, I would appreciate a further Hibernate extension to support this in order to automatically generate proper table/column names from quoted identifiers. Or am I just missing a configuration setting?

As a concrete suggestion, I could imagine the following naming strategy:
- prior to concatenation of table/colum names, discard any surrounding backticks
- after concatenation, re-add surrounding backticks if any part of the generated identifier was originally quoted

Thanks in advance to anybody sharing his/her thoughts.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 11:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you open a JIRA issue, I need to fix that

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 1:44 pm 
Newbie

Joined: Thu Jun 22, 2006 6:35 am
Posts: 5
OK, the issue has been opened:
http://opensource.atlassian.com/project ... se/ANN-476

Thanks for your quick reply and keep up the good work!


Benjamin


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