-->
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.  [ 2 posts ] 
Author Message
 Post subject: Create table fails: Null Column in PK not allowed in MSSQL
PostPosted: Mon May 10, 2010 9:02 am 
Newbie

Joined: Mon May 10, 2010 8:40 am
Posts: 2
Hi!
My problem:

@ElementCollection
@CollectionTable(name = "xxx", joinColumns = @JoinColumn(name = "depends", nullable = false))
@Column(name = "dependent", nullable = false)
public Map<String, String> getDependents() {
return this.dependents;
}

generates the following DDL script:

create table xxx (depends numeric(19,0) not null, dependent varchar(255) not null, dependents_KEY varchar(255) null, primary key (depends, dependents_KEY))
As you can see, I managed to get the "not null" behind every column except the last one: dependents_KEY.
so MS SQL fails to create the table.

"dependents_KEY varchar(255) null" doesn't work as NULL Primary Keys are not allowed in MS SQL. What can I do to force hibernate to generate
dependents_KEY varchar(255) NOT null

Thank you very much!
Java Junky


Top
 Profile  
 
 Post subject: Re: Create table fails: Null Column in PK not allowed in MSSQL
PostPosted: Mon May 10, 2010 9:22 am 
Newbie

Joined: Mon May 10, 2010 8:40 am
Posts: 2
Ok, got it:

@ElementCollection
@CollectionTable(name = "xxx", joinColumns = @JoinColumn(name = "depends", nullable = false))
@Column(name = "dependent", nullable = false)
@MapKeyColumn(name = "dependent_key", nullable = false)

I missed the MapKeyColumn!


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.