Hibernate tips 1

hibernate configure

inverse = true : parent side update wont have any result, on the reverse side, the changes will happen in database.


Session Lock

reattach the detached object


Session merge

1. dont associated the instance with session

2. If new object, will save a copy and return persisted object

3. If detached, will copy over to attached object (if no attached object, need load from database)

 

If persist object associated with trancient object, persist attached object will cascade to the transcient object as well if the cascade="all"....

 

OID can not be changed, better private setID()


Hibernate update

1. throw exception when wanna updating a detached object, while session already has object with same ID

2. can not update object which wasn't in database.


Condition of transcient object

1. OID is null

2. version is null

3. configure file:  id has unsaved-value, OID = unsaved-value

4. configure file: version value = unsaved-value for version

5. hibernate inteceptor , isUnsaved() return TRUE


Session delete

1. if attached - just delete it

2. if not attached - merge it first, then delete it


Session update & database trigger

to overcome this problem

1. after flush, refresh the updated object

2. useless update will trigger unnecessary database trigger, need set "Select-before-update" to compare object to know whether we need update the object.


 HQL

1. hql will match case insensitive data e.g. name = 'Tom'/'tom'/TOM', will match all of them.

你可能感兴趣的:(Hibernate)