Reputation: 916
Hibernate verstion is 3.x
Below is the table structure,
firstname | lastname | salary
-----------------------------------
firstname | lastname | 100
firstname | lastname | 500
firstname | lastname | 1000
Below is the java code,
@Entity
@Table(name="TABLE_NAME",schema="SchemaName",
uniqueConstraints={@UniqueConstraint(columnNames={"firstname","lastname"})})
Though I have mentioned the unique constraint on the tuples 'firstname' and 'lastname', am still able to add rows with the same firstname and lastname values.
I thought, I would get HibernateException
or otherwise and I won't be allowed to add
same firstname and lastname values for multiple rows. I don't have unique constraint
created at the database level. Its there just in the code.
Why am I able to add duplicate rows? Or my understanding of unique constraint is wrong?
Upvotes: 0
Views: 98