hibernate module

The hibernate module defines high level functions on top of Hibernate API.

hb = openHibernate ( persisntet_classes {, Properties properties } )

Creates a Hibernate Session object and returns an object that the Session object is associated with, and can be used for query/update/insert operations.

persisntet_classes is a set of persistent classes that can iterate with for/foreach statement (array/Collection/Iterator/Enumeration).

hb = openHibernate([class Record], loadProperties("hibernate.properties"))
hb . save ( Object object )
hb . update ( Object object )
hb . saveOrUpdate ( Object object )

save() saves a persisntent object to the Hibernate storage. update() updates a persisntent object in the Hibernate storage. saveOrUpdate() saves or updates a persisntent object depending upon the value of identity property.

These operations are executed during a new transaction.

account = Account()
account.name = "Foo"
account.email = "foo@bar"
hb.save(account)
hb . query ( String query_string )

Returns a Query object that can be used with other functions, such as find() and list().

See 'Hibernate Query Language' for the detailed description of the query language.

q = hb.query("from Person where name like 'john%'")
john = hb.find(q)
hb . find ( String query_string ) or
( Query query )

Search a persistent object with query and return the first one found. Returns null if no objects are found.

rec = hb.find(Account, "from wiki.WikiRecord wiki where name = 'FrontPage'")

The parameter can be a Query object which can be obtained from hb.query() function.

q = hb.query("from wiki.WikiRecord wiki where name='FrontPage'")
rec = hb.find(q)
hb . delete ( Object object )

Delete a persistent object from the Hibernate storage.

john = hb.find("from Person where name ='John'")
hb.delete(john)
hb . list ( String query_string ) or
( Query query )

Execute a query and returns the result as a collection of persistent objects.

q = hb.query("from Person where age < 20")
kids = hb.list(q)
printAll(kids)
hb . transaction ( func(Session) )

transaction() executes the specified function during a transaction.

hb.transaction(function (session){
  for (i = 0; i < num; i++){
    session.save(account[i])
}
})
hb . session

Returns a Session object.

e.g.
import("net.sf.hibernate.*")

session = hb.session
tran = session.beginTransaction()
catch(HibernateException, function (e) tran.rollback())
account = Account()
account.name = "Foo"
account.email = "foo@bar"
session.save(account)
...
tran.commit()
hb . close ( )

Close the Hibernate SessionFactory.

hb.close()