Hi
I have a collection of elements in one of my entities and I would like to use the annotation CollectionOfElements. This is my code:
Code:
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "COLLECTION_TABLE",
joinColumns = @JoinColumn(name = "OBJECT_ID"),
)
@Basic(fetch=FetchType.LAZY)
private final Set<MyClass> objects = new HashSet<MyClass>();
Code:
@Embeddable
public class MyClass{
@Temporal(TemporalType.TIMESTAMP)
@Column(updatable=false, insertable=false, nullable=false, columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP")
@Generated(GenerationTime.NEVER)
private Date lastModified;
}
This is quite a useless jointable, but it illustrates my case.
If I generate the schema, the result table will be:
create table COLLECTION_TABLE (
OBJECT_ID numeric(19,0) not null,
lastModified datetime DEFAULT CURRENT_TIMESTAMP not null,
primary key (OBJECT_ID, lastModified)
)
Why is "lastModified" part of the primary Key?? Do I have any way to tell hibernate not to include lastModified in the primary key?
The problem is that any insert/update performed by Hibernate includes all the column, even when lastModified is always null (will be generated by the database)
Code:
insert into
USER_GROUPS
(OBJECT_ID, lastModified)
values
(?, ?)
and should be
Code:
insert into
USER_GROUPS
(OBJECT_ID)
values
(?)
I'm gettin SQL-SERVER errors because hibernate insists in include LASTMODIFIED = NULL in every insert/update.