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: Hibernate's handling of unmapped columns.
PostPosted: Tue Apr 24, 2007 1:12 pm 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
I have looked through the documentation and searched the forums, but i can't seem to find an answer to this question. So here goes:



If I have a table with the following columns:

id - int
First name - string
last name - string
misc - string


Ifi map a POJO to this table, but only the id, first name and last name columns are mapped. When an update occurs, does Hibernate delete the data in the misc column, or will it simply ignore it?

The basic gist is, i have tables that have 30+ columns on them. however my app will only need to update maybe 10 or so. The data in the other columns needs to stick around. Do i have to map these columns to ensure that an update doesn't wipe out the data. Or if i don't map them, will the Hibernate persistence manager simply treat them as if they weren't there?

All of the examples and other classes i've used, have a 1:1 property-to-column mapping. So when i see the logging of the updates/inserts, i see all of the columns on the table in the SQL statement. I would assume that if i don't map the column, then the insert/update statement doesn't contain that column its list for updates, nor a NULL in the value set in the corresponding location.

Unfortunately I don't have permissions to create some test tables in the database, otherwise i'd just try that. I am hoping that someone could simply provide a "yes/no" and a short explanation. Thanks in advance!

-B


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 2:39 pm 
Newbie

Joined: Fri Apr 20, 2007 3:46 pm
Posts: 15
If you do not provide columns/properties in the mapping then hibernate will not touch those unmapped columns. Of course if you delete the whole row then all the columns will get deleted. But if you just want to do updates/inserts you can certainly omit columns from mapping and they will not be touched.

Another approach is to map all the columns/property and specified
update="false" and insert = "false" in your mapping file.
This will ensure that those special properties/columns can not be inserted or updated

Third approach is just to map them in the mapping but to use the following attributes in the class mapping
dynamic-update="true"
This will ensure that when are you doing update only property that you have actually changed will be listed in the update statement


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.