java


Hibernate hbm2ddl.auto update does not drop columns with mysql


Its adds new ones, but as far as I can see it does not drop the old ones ?
When I say old ones, I mean properties of entity objects that are now completely removed,where previously they were present and annotated with #column
Are my only options to drop the col manually or change the config value to create ? Neither of which are particularly charming.
Or something else ?
For what it's worth, never EVER use hbm2ddl.auto on any live/production database.
Yes, it is "working as intended" that "update" doesn't drop any columns that are not referenced (probably to allow you to use "legacy" databases that have columns that are not used by your hibernate app, but may be used by external applications). However, in certain circumstances, hibernate can drop and recreate columns if, for instance, you change the datatype in your entity. That is one of the reasons you should never use it for any production system.
Personally, I would never trust an automated "black box" framework to handle changes to the datamodel in anything but strictly local/dev environments. I have always set it up so in the local dev environments, you may do create-drop. Once it's time to start promoting your app to central test/stage and then prod, all database changes are done by DBA:s with good old fashioned DDL scripts. Data is far too valuable to risk on a potential bug or unexpected behavior in hibernate (or any other ORM/automated framework). I even make sure that the database user configured in my applications doesn't even have create/drop/alter privileges in the database, just to prevent disasters happening due to bad configuration in hibernate.
So, to answer your question - if you want hibernate to always maintain your database reflecting your entities exactly, "create-drop" is your only option. Just don't ever use it on anything but local dev databases.
I'd have a look into liquibase for keeping your database in sync with your enitities. Maybe a bit of an overkill but well worth it.

Related Links

Active Directory Authentication Using Java
How ObjectOptimisticLockingFailureException thrown, while selecting or read a row in hibernate?
get “ Only one root element allowed” when try to read file
showing null pointer exception with data added into array list [duplicate]
Swing - My class extends JTextPane and calling first my append() and then super.setText() add additional line break
How to retrieve data from response? - Retrofit 2
what are the differences between String method split(String str, int len) and split(String str)?
Multilevel static nested class producing wrong output
Music player in Android studio
Android - Displaying a static activity within another static activity
tableViewTender.setPlaceholder not working in javaFX
maintaining data consistency in spring
JavaFX switching scenes in object oriented program
Found interface org.apache.hadoop.mapreduce.Counter, but class was expected
How to create a JMS queue/topic programmatically in wildfly 10 server.
How to serialize a DTO to key-value list?

Categories

HOME
ibm-bluemix
testng
listview
oracle11g
gremlin
heroku
include
cmd
infragistics
export-to-csv
static-libraries
foselasticabundle
http-status-code-504
pythonanywhere
nhibernate-envers
contextmenu
kryo
visjs
abi
ehcache
smb
vlsi
react-css-modules
bootstrap-material-design
fopen
social-media
spring-mybatis
gitignore
lightswitch-2013
ecto
semantic-versioning
azure-sql-database
wallpaper
sequential
adobe-premiere
web-mining
retina-display
lto
android-fingerprint-api
leading-zero
graphenedb
mesos-chronos
android-tabhost
qwt
flickr-api
network-flow
theming
celery-task
jspdf-autotable
yt-project
wdf
android-fonts
measures
pcf
player
firebaseui
pagerank
cloudbees
browser-link
freelancer.com-api
separator
jmeter-maven-plugin
atk4
security-testing
graph-drawing
oberon
skos
notify
truevault
rake-task
tt-news
qcodo
bitcoinj
xojo
openexr
concurrent-collections
oam
.aspxauth
flash-builder4.5
excel-2003
dataadapter
ember-app-kit
wsdl-2.0
e4x
jquery-knob
nsnetservice
broken-links
jspinclude
bubble-chart
reddot
ohm
bigcouch
nsdatecomponents
data-loss
joyent
krl
yslow
zend-translate
sortable-tables
infrastructure
dbal
geneva-server
wsdl.exe

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App