Hi,
I've a class with a constructor and method:
Code:
public TableDefn(String internalTableName) {
if (internalTableName == null) {
this.internalTableName = (new RandomString()).toString();
} else {
this.internalTableName = internalTableName;
}
}
public String getInternalTableName() {
return this.internalTableName;
}
If you supply an internalTableName to the constructor, it uses that as the object's ID, otherwise it generates one itself.
I'm new to hibernate and want to use annotations to mark up my objects. The question is, could you use @GeneratedValue as follows, or would it be best not to?
Code:
public TableDefn(String internalTableName) {
if (internalTableName != null) {
this.internalTableName = internalTableName;
}
}
@Id
@GeneratedValue
public String getInternalTableName() {
return this.internalTableName;
}
i.e. to have hibernate generate a value if you don't specify one, rather than the code.
I know this would be a bad idea if using sequences in an SQL database directly - it may be possible for the db to generate a value that already exists for example. In hibernate, is this any different?
Regards,
Oliver[/code]