Hello,
I'd like to introduce Hibernate scripting, a new feature in the JudoScript language, and hope to get some feedback from active Hibernate developers.
The crux of Hibernate scripting in JudoScript is demonstrated as follows:
8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
import com.foo.bar.*;
// Initialize Hibernate:
hib::setup (
hibernate.connection.url = 'jdbc:mysql://localhost/test',
hibernate.connection.username = 'user',
hibernate.connection.password = 'pass',
hibernate.hbm2ddl.auto = 'update',
judoscript.echo = true
)
// the classes in the object model (under com.foo.bar)
Foo,
Bar
;
// Create a few new objects and save them:
for i from 0 to 10 {
x = new java::Foo;
x.prop1 = 'abc';
println 'Before save: x.id = ', x.id;
hib::save(x);
println 'After save: x.id = ', x.id;
}
// HQL Query:
hib::query qry: // or hib::iterate
from Foo f
where f.id > 1 and f.id < 10
;
for x in qry { // qry holds a list of Foo's.
println x;
}
// HQL Delete; with bind variables:
hib::delete:
from Foo f
where f.id > :startIdx and f.id < :endIdx
; with startIdx:Long = 3, endIdx:Long = 5;
// Done.
hib::close; // (closes the per-thread Session instance)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >8
Note, this program works with both Hibernate2 and Hibernate3.
For more details, see:
http://www.judoscript.com/books/judoscr ... s/hib.html
Also, heavily related topics are Java scripting and JDBC scripting:
http://www.judoscript.com/books/judoscr ... /java.html
http://www.judoscript.com/books/judoscr ... /jdbc.html
Again, feedback will be much appreciated! (feedback link is on the website.)
Thanks,
James Huang,
author of JudoScript