Hello,
there seems to be an insert bug (em.persist) in the current Hibernate version.
The entity's primary key is a Long value, auto generated.
Entity:
Code:
@Entity
@Table(uniqueConstraints = @UniqueConstraint(colmnNames = {name}))
public class MyClass {
private Long id;
private String name;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
...
}
Now I want to insert two objects: The first's name property is set to "foo" and second's one also to "foo". Both objects are in a collection and inserted within one transaction.
Ok, the first insert succeeds and the second fails because of the unique constraint. The pretty wired thing is that the first object has an id set although it's not in the database.
A rollback occurs and I am definitely sure that the id in the first object must not be set!
cheers,
Kasperl