is using @GeneratedValue annotation on non-id column possible ?
by Ghislain Carignan
Hello,
I would like to use a @ GeneratedValue annotations on a non-id column, is that possible?
The annotation is also used on the id :
@Id @GeneratedValue (generator="naid-uuid") @GenericGenerator(name="naid-uuid", strategy="com.netappsid.erp.UUIDGenerator") @Type(type="com.netappsid.datatypes.UUIDUserType")
@AccessType(value="field")
public Serializable getId()
{
return id;
}
This is the field I'd like to auto-increment.
@Column(name = "identifier", insertable = false, updatable = false)
@Generated(value=GenerationTime.INSERT)
@GeneratedValue(strategy=GenerationType.IDENTITY)
@AccessType(value="field")
public Long getIdentifier()
{
return identifier;
}
In PostgreSQL this column will be an int8 instead of a bigserial.
In SQL Server this column will be a numeric (19,0) without identity
Thank you in advance,
Ghislain
14 years, 2 months
Question about annotations
by Daniel Rindt
hello,
i am new to hibernate, so please grant me some questions.
My hibernate session uses the MySQLDialect.
1. Empty fields in the Model are not NULL in db. My definition:
@Size(max = 50)
private String title;
In the db is later an empty string, the @NotNull annotation also
is not working because its an emptry String ""
2. Unique fields are not working?
@Email
@Column(unique = true)
@Size(min = 7, max = 50)
private String email;
The email field should be unique in database, but it is not. And in
the structure of the table also not defined as unique.
Someone can give me a clue please?
TIA
Daniel
14 years, 3 months