This blog is mainly about Java...

Wednesday, May 7, 2008

Seam-gen problems when having MyISAM as engine in MySQL

I tried running seam-gen on an existing MySQL database, where the engine is MyISAM.
Jboss-seam-2.0.1.GA is the version of seam I was running.

The strangest thing happened. When I reversed engineered the database to create entity beans, the foreign keys where not Objects like it is normally, but rather String.
For instance, in our Address entity bean, I have a foreign key that is mapped to the Country entity bean.
Normally the should look something like this:

@Table(name = "address")
public class Address implements {

private Integer addressId;
//The ID
private Country country; //The foreign key

However, the foreign key was generated like this:
private String countryId; //The foreign key

But when I changed the MySQL engine to use InnoDB instead, and I ran a new seam-gen, it was generated correctly.

Just a heads up if someone encounters the same problem. I would guess it is a bug in either seam or hibernate. Probably hibernate, since it is hibernate that does the generation.


Anonymous said...

It is not a bug. MySQL MyISAM engine doesn't support foreign keys but InnoDB does.

Shervin Asgari said...

Well what do you know :-)
No wonder it didnt work then. Thank you for clarifying.

Sanjay Mazumder said...


I'm not able to generate my Seam project with proper foreign key implementation with Seam gen. I've tried everything and even though it's not working.

Can you please mail me a sample project generated by Seam gen where the database has foreign keys.

My email id is



Shervin Asgari said...

You can always view the sample projects in seam. Instead, tell me what your problem is. What database are you using? As this blog post said, you cannot have MyISAM in MySQL. You should try INNODB.