The hibernate module defines high level functions on top of Hibernate API.
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"))
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)
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)
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)
Delete a persistent object from the Hibernate storage.
john = hb.find("from Person where name ='John'")
hb.delete(john)
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)
transaction() executes the specified function during a transaction.
hb.transaction(function (session){
for (i = 0; i < num; i++){
session.save(account[i])
}
})
Returns a Session object.
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()
Close the Hibernate SessionFactory.
hb.close()