java - What hibernate do with unmapped column? -
suppose there class that:
public class entity { private long id; private string name; }
and table 3 columns: id, name , address.
create table entity ( id number(9,0), name varchar2(255), address varchar2(1000),
then en insert performed:
insert entity (id, name, address) values (1, "a", "b")
then load , update hibernate entity:
session session = ... entity entity = session.get(entity.class, 1);
then update name , save again:
entity.setname("newname"); session.save(entity);
so address column value - null or b
? hibernate provide stgrategies such situations or have add address
field entity , mark @column(updatable=false, insertable = false)
?
if put following properties in persistence.xml(or have defined hibernate properties)
<property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="false"/>
then see queries executed hibernate when server run in debug mode logged configured debug.
if entity
public class entity { private long id; private string name; private string secondname; //getters & setters }
then executing below hql
select e entity e e.id = 121
would produce results similar to
select entity0_.id id1_63_, entity0_.name name6_63_, entity0_.secondname secondname6_63_, yout_db.entity entity0_ entity0_.id = 121
you see here select * entity
not executed instead fields class fetched , added query. if have ignored field db not taking part in queries.
for select-update same thing happens.
entity.setname("newname"); session.save(entity);
below formatted query if update entity:
update your_db.entity set name = ? secondname = ? id = ?
this query executed if 1 field changed.
Comments
Post a Comment