You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by angelochen <an...@yahoo.com.hk> on 2011/10/24 10:15:52 UTC

Sharing entity class and hibernate.cfg.xml with Groovy

Hi,

This might not be very related to t5, but quite useful for t5 users :

I want to access the database using the entities defined in T5 app and
hibernate.cfg.xml,
in the hibernate.cfg.xml I have :

 <mapping class="org.t5.entities.Book" />

but when run the script, i got :

Caught: org.hibernate.hql.ast.QuerySyntaxException: Book is not mapped [from
Book]


here is the code in Groovy:

package demo

import javax.persistence.*
import org.hibernate.cfg.*
import org.t5.entities.*

// 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'),
])

def configureHibernate() {
    def config = new AnnotationConfiguration()
	File f = new File("hibernate.cfg.xml")
   	config.configure(f)
    return config
}

def factory = configureHibernate().buildSessionFactory()

// store some books
def session = factory.currentSession

session = factory.currentSession
tx = session.beginTransaction()
def books = session.createQuery("from Book").list()
println 'Found ' + books.size() + ' books:'
tx.commit()



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Sharing-entity-class-and-hibernate-cfg-xml-with-Groovy-tp4931694p4931694.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org