My goal is to create an entity device with a unique IMEI field, and I would like to use it as a primary key and specify it during device registration (specified manually when creating an entity). I am using Spring roo tool for development and sleeping as an ORM.
When I state this in an entity declaration:
@RooJavaBean @RooToString @RooJpaActiveRecord(identifierField = "IMEI", identifierType = String.class) public class Device {...}
I get this generated:
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "IMEI") private String Device.IMEI;
When deploying a project to a server with MySQL DB, I get this error:
2013-03-17 20:03:23,136 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table device (imei varchar(255) not null auto_increment, model varchar(255), name varchar(255) not null, version integer, primary key (imei)) 2013-03-17 20:03:23,136 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Incorrect column specifier for column 'imei'
Then I redefine the generated field with
@Id @GeneratedValue(generator = "org.hibernate.id.Assigned") @Column(name = "the_code") private String code;
(I found it here )
But still getting an error. Then I changed the code just like this:
@Id private String IMEI;
and then it works fine and asks me to specify the imei field before saving the object.
My questions:
Is it correct to use my custom field as an identifier?
Is this normal for String?
is it normal that it is not generated with hibernate but taken from an imei device?
What is org.hibernate.id.Assigned?
Why doesn't the generated roo code for @RooJpaActiveRecord (identifierField = "IMEI", identifierType = String.class) not work?
Is it possible to create a String automatically generated primary key?
What is the default GeneratedValue strategy value (my last case)?
I read the official document, but did not understand everything, please send me to an article where I can read about all this.
Thank you, sorry for the long question.