-->
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: hbm2ddl mysql alter table statement from annotated class
PostPosted: Wed Jun 04, 2008 12:17 am 
Newbie

Joined: Thu May 29, 2008 1:30 am
Posts: 4
Hi,

I'm using annotations and hbm2ddl. I'm having a problem with the outputted alter table statement:

It outputs:

Code:
alter table tdrs.Reservation
        add constraint FK63EEBAC662D7DD8
        foreign key (empNo)
        references tdrs.User;


But mysql will not let me execute that statement, giving the message

Code:
Can't create table '.\tdrs\#sql-5bc_518.frm' (errno: 150)


My annotated classes are:

Code:
@Entity
public class User
{
@Id
private String empNo;
private String firstName;
private String lastName;
private Timestamp dateModified;
private Timestamp dateAdded;
}



Code:
@Entity
public class Reservation
{
  @Id
  private Long reservationId;
  @ManyToOne(cascade = ALL)
  @JoinColumn(name = "empNo", referencedColumnName = "empNo")
  private User user;
  //other data
}


I've tried all sorts of other formats for the joinColumn annotation as well, but with no success.

The way that I can get mysql to execute the statement is by manually changing it to

Code:
alter table tdrs.Reservation
        add constraint FK63EEBAC662D7DD8
        foreign key (empNo)
        references tdrs.User [b](empNo)[/b];


Is there any way to force hbm2ddl to assign the bit in bold above? Or am I missing something else?

Cheers.

[/quote][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 8:55 pm 
Newbie

Joined: Thu May 29, 2008 1:30 am
Posts: 4
I guess this should have been obvious but the solution was to have the correct dialect (mysql) under org.hibernate.dialect.MySQLDialect.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 11:54 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
lol

Sometimes the simplest of mistakes take the longest time to diagnose.

I feel your pain.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.