
下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
package demoimport javax.persistence.*import org.hibernate.cfg.*// javax.transaction jta.jar added manually to ivy repo@Grapes([ @Grab(group='org.hibernate',module='hibernate-annotations',version='3.4.0.GA'),@Grab(group='org.slf4j',module='slf4j-simple',version='1.4.2'),@Grab(group='hsqldb',module='hsqldb',version='1.8.0.7'),@Grab(group='javassist',module='javassist',version='3.4.GA'),])@Entity class Book { @ID @GeneratedValue(strategy = GenerationType.auto) public Long ID public String author public String Title String toString() { "$Title by $author" }}def hibProps = [ "hibernate.dialect": "org.hibernate.dialect.HsqlDialect","hibernate.connection.driver_class": "org.hsqldb.jdbcDriver","hibernate.connection.url": "jdbc:hsqldb:mem:demodb","hibernate.connection.username": "sa","hibernate.connection.password": "","hibernate.connection.pool_size": "1","hibernate.connection.autocommit": "true","hibernate.cache.provIDer_class": "org.hibernate.cache.NoCacheProvIDer","hibernate.hbm2ddl.auto": "create-drop","hibernate.show_sql": "true","hibernate.transaction.factory_class": "org.hibernate.transaction.JDBCTransactionFactory","hibernate.current_session_context_class": "thread"]def configureHibernate(props) { def config = new AnnotationConfiguration() props.each { k,v -> config.setProperty(k,v) } config.addAnnotatedClass(Book) return config}def factory = configureHibernate(hibProps).buildSessionFactory()// store some booksdef session = factory.currentSessiondef tx = session.beginTransaction()session.save(new Book(author:'DIErk et al',Title:'Groovy in Action'))session.save(new Book(author:'Craig',Title:'Spring in Action'))tx.commit()// find some bookssession = factory.currentSessiontx = session.beginTransaction()def books = session.createquery("from Book").List()println 'Found ' + books.size() + ' books:'books.each { println it }tx.commit() 以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的在groovy中如何使用Hibernate全部内容,希望文章能够帮你解决在groovy中如何使用Hibernate所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)