[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1935) Hibernate produces invalid "create table" SQL for Maps on SQL Server 2000
Hardy Ferentschik (JIRA)
noreply at atlassian.com
Thu Oct 11 09:59:39 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28405 ]
Hardy Ferentschik commented on HHH-1935:
----------------------------------------
There seem to be a bug in the schema export for SQLServer. The generate table create statement looks like this:
> create table A_B (A_id int not null, b_id int not null, mapkey varchar(255) null, primary key (A_id, mapkey), unique (b_id));
The problem is 'mapkey varchar(255) null' - you cannot have a nullable column in a multicolumn primary key. For other databases the script seems to be ok. , eg postgres
> create table A_B (A_id int4 not null, b_id int4 not null, mapkey varchar(255), primary key (A_id, mapkey), unique (b_id));
There is a workaround using the @MapKey annotation
@OneToMany
@MapKey(columns=@Column(name="mapkey", nullable=false))
private Map<A, B> b;
Using the @Column you can make sure that the mapkey column will be nullable.
> Hibernate produces invalid "create table" SQL for Maps on SQL Server 2000
> -------------------------------------------------------------------------
>
> Key: HHH-1935
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1935
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.2.0.cr2
> Environment: Hibernate 3.2.0.cr2
> Microsoft SQL Server 2000
> Reporter: Bill Johnson
>
> I have two cases where Hibernate3 produces invalid SQL for MS SQL Server 2000:
> Case 1:
> @CollectionOfElements
> @org.hibernate.annotations.MapKey
> protected Map<String, String> properties;
> Case 2:
> @ManyToMany
> @MapKeyManyToMany
> private Map<A, B> b;
> In Case 2, A and B are entities creating a ternary relationship between the parent class, A and B, and I get the following log output:
> ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <Unsuccessful: create table A_B (A_id numeric(19,0) not null, b_id numeric(19,0) not null, key_id numeric(19,0) null, primary key (A_id, key_id), unique (key_id))>
> ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <Cannot define PRIMARY KEY constraint on nullable column in table 'A_B'.>
> Hibernate should not attempt to create a nullable primary key column by default on MS SQL Server.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list