-->
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.  [ 5 posts ] 
Author Message
 Post subject: hbm2ddl and annotations
PostPosted: Mon Feb 12, 2007 7:24 am 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
I have a few annotated classes that I generate the database schema from using hibernate.hbm2ddl.auto=create-drop. This works well for all classes except the Group class, the table for this is not created. However if I add a @Table(name="groups") after @Entity it is created (named "groups"). If I try @Table(name="group") it will not work... Any idea why?

Hibernate version: 3.2.1.ga

Mapping documents:
package com.mypackage;
/* imports */

@Entity
public class Group implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int groupid = -1;

@Column( nullable=false, length=32 )
private String name;

/* getters and setters */ }


Name and version of the database you are using: MySQL 5.0.22


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 10:28 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi daijavad,

since GROUP is a reserved word in SQL it is not a valid tablename (as opposed to GROUPS which isn't a SQL-Keyword), so there should be some kind of SQLException in your log indicating the failed "create"-attempt.

Greets

piet


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 11:52 am 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
piet.t wrote:
since GROUP is a reserved word in SQL it is not a valid tablename (as opposed to GROUPS which isn't a SQL-Keyword), so there should be some kind of SQLException in your log indicating the failed "create"-attempt.


Thanks piet.t!

I thought it may have something to do with reserved keywords, but MySQL is not complaining when I am creating a table named "group" through the MySQL query browser.

Could there be some escaping missing at some level here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 10:54 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
You're right, it's working when you put the table-name in `...` - but I think that's some specific mysql-Extension of standard-sql, so I think hibernate is right in not using it....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 11:46 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
I think I just found the solution to your problem:
you can convince hibernate to quote names in the generated SQL:
Just use a mapping like
<class name="LineItem" table="`Line Item`">....
(observe the backticks `)
hibernate will then quote the name on SQL-generation, it will even choose the right quote-character for your SQL-Dialect.


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