Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: @ManyToMany Join Table uses not-nullable columns
PostPosted: Thu Aug 03, 2017 9:41 am 
Newbie

Joined: Thu Aug 03, 2017 9:25 am
Posts: 6
Hello,
We are migrating from Kodo (JDO) to Hibernate and when creating DDL scripts from JPA and Hibernate annotations, Hibernate SchemaExport adds NOT NULL constraints on columns in join tables.
However, we are using a legacy schema where join tables allow null columns in join tables and it is actually used - we have a lot of records where one field is null.
So far we have been using Kodo and it had no problems with it. Kodo did not create that NOT NULL constraints.
I found in Hibernate sources that it is hardcoded in method
Code:
Ejb3JoinColumn.buildJoinTableJoinColumns
with a comment
Quote:
//I break the spec, but it's for good

Is it possible to stop Hibernate from creating NOT NULL constraints? If so, could it cause other problems when reading or saving data from/to such a join table where some fields are null?
We are using Hibernate 4.2.18.


Top
 Profile  
 
 Post subject: Re: Join Table nullable column
PostPosted: Thu Aug 03, 2017 10:10 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1435
The value is indeed hard coded and you can't override it with the @JoinColumn annotation.

However, why do you use the auto-generated schema? That's only useful for prototyping and maybe for generating the first schema skeleton that you validate prior to using it as the first schema migration script.

You should be using an automatic schema migration tool such as Flyway instead.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.