-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: CollectionOfElements and generated primary keys
PostPosted: Tue Nov 25, 2008 1:35 pm 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.