seam jpql测试方法

环境:
Eclipse Platform
Version: 3.3.2
Build id: M20080221-1800

JBossAS Tools
Version: 1.1.2.GA

jboss-4.2.0.GA

jboss-seam-2.0.2.SP1

步骤
1.seam-gen 生成我的第一个SEAM工程 myfirstseam
生成的seam-gen/build.properties信息如下:
#Generated by seam setup
#Tue Dec 30 17:23:53 GMT 2008
hibernate.connection.password=
workspace.home=c\:/myseam
model.package=com.mydomain.model
hibernate.default_catalog=localDB
driver.jar=../lib/hsqldb.jar
action.package=com.mydomain.myfirstseam
test.package=com.mydomain.test
database.type=hsql
richfaces.skin=ruby
hibernate.default_schema=INFORMATION_SCHEMA
database.drop=n
project.name=myfirstseam
hibernate.connection.username=sa
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
project.type=ear
icefaces.home=
database.exists=n
jboss.home=D\:/TDDownload/jboss-4.2.0.GA
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.url=jdbc\:hsqldb\:${jboss.server.data.dir}${/}hypersonic${/}localDB
icefaces=n



工程类路径文件内容如下(.classpath)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" output="classes/model" path="src/model"/>
	<classpathentry kind="src" output="classes/action" path="src/action"/>
	<classpathentry kind="src" output="classes/test" path="src/test"/>
	<classpathentry kind="src" path="resources"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="lib" path="bootstrap"/>
	<classpathentry kind="lib" path="lib/hibernate-validator.jar"/>
	<classpathentry kind="lib" path="lib/hibernate.jar"/>
	<classpathentry kind="lib" path="lib/hibernate-annotations.jar"/>
	<classpathentry kind="lib" path="lib/hibernate-commons-annotations.jar"/>
	<classpathentry kind="lib" path="lib/hibernate-entitymanager.jar"/>
	<classpathentry kind="lib" path="lib/jboss-seam.jar" sourcepath="lib/src/jboss-seam-sources.jar"/>
	<classpathentry kind="lib" path="lib/jboss-seam-debug.jar"/>
	<classpathentry kind="lib" path="lib/jboss-cache.jar"/>
	<classpathentry kind="lib" path="lib/jbpm-jpdl.jar"/>
	<classpathentry kind="lib" path="lib/antlr.jar"/>
	<classpathentry kind="lib" path="lib/jgroups.jar"/>
	<classpathentry kind="lib" path="lib/jsf-facelets.jar"/>
	<classpathentry kind="lib" path="lib/jstl.jar"/>
	<classpathentry kind="lib" path="lib/jsf-api.jar"/>
	<classpathentry kind="lib" path="lib/servlet-api.jar"/>
	<classpathentry kind="lib" path="lib/testng.jar"/>
	<classpathentry kind="lib" path="lib/jboss-el.jar"/>
	<classpathentry kind="lib" path="lib/el-api.jar"/>
	<classpathentry kind="lib" path="lib/mvel14.jar"/>
	<classpathentry kind="lib" path="lib/drools-core.jar"/>
	<classpathentry kind="lib" path="lib/drools-compiler.jar"/>
	<classpathentry kind="lib" path="lib/janino.jar"/>
	<classpathentry kind="lib" path="lib/antlr-runtime.jar"/>
	<classpathentry kind="lib" path="lib/mail.jar"/>
	<classpathentry kind="lib" path="lib/persistence-api.jar" sourcepath="D:/Program Files/Java/jdk1.5.0_16/src.zip"/>
	<classpathentry kind="lib" path="lib/ejb-api.jar"/>
	<classpathentry kind="lib" path="lib/jsr250-api.jar"/>
	<classpathentry kind="lib" path="lib/jta.jar"/>
	<classpathentry kind="lib" path="lib/core.jar"/>
	<classpathentry kind="lib" path="lib/jboss-embedded-api.jar"/>
	<classpathentry kind="lib" path="lib/hibernate-search.jar"/>
	<classpathentry kind="lib" path="lib/richfaces-api.jar"/>
	<classpathentry kind="lib" path="lib/hsqldb.jar"/>
	<classpathentry kind="lib" path="lib/lucene-core.jar"/>
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-seam-2.0.2.SP1/lib/test/jboss-embedded-all.jar"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-seam-2.0.2.SP1/lib/test/thirdparty-all.jar"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-seam-2.0.2.SP1/lib/test/hibernate-all.jar"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-seam-2.0.2.SP1/lib/jboss-deployers-core-spi.jar"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-seam-2.0.2.SP1/lib/jboss-embedded-api.jar"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-seam-2.0.2.SP1/lib/jboss-deployers-client-spi.jar"/>
	<classpathentry kind="lib" path="D:/TDDownload/jboss-4.2.0.GA/server/default/lib/jboss-ejb3x.jar"/>
	<classpathentry kind="output" path="test-build"/>
</classpath>


D:/TDDownload/jboss-seam-2.0.2.SP1/lib/路径下的JAR是用于测试的JAR

用于测试的文件夹结构如下:
└─test
    │  readme.txt
    │  RegActionTest.java
    │
    └─META-INF
            persistence.xml

RegActionTest.java文件内容如下:
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;

import org.jboss.seam.mock.SeamTest;
import org.junit.Test;

public class RegActionTest extends SeamTest {
	@Test
	public void testReg() {

		EntityManager em = Persistence
				.createEntityManagerFactory("myfirstseam1")
				.createEntityManager();
		em.getTransaction().begin();
		Query q= em.createNativeQuery("SELECT USER FROM INFORMATION_SCHEMA.SYSTEM_USERS");
		q.setFirstResult(1);
		q.setMaxResults(10);
		List list = q.getResultList();
		
		em.getTransaction().commit();
		em.close();
	}
}

persistence.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence>
	<persistence-unit name="myfirstseam1"
		transaction-type="RESOURCE_LOCAL">
		<properties>
			<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
			<property name="hibernate.connection.driver_class"
				value="org.hsqldb.jdbcDriver" />
			<property name="hibernate.connection.username" value="sa" />
			<property name="hibernate.connection.password" value="" />
			<property name="hibernate.connection.url"
				value="jdbc:hsqldb:localDB" />
			<property name="hibernate.show_sql" value="true"/>
		</properties>
	</persistence-unit>
</persistence>

运行RegActionTest的JUNIT的SQL的输出结果如下:
Hibernate: SELECT limit ? ? USER FROM INFORMATION_SCHEMA.SYSTEM_USERS

终于完成我的第一个SEAM JPQL UNIT测试环境!

你可能感兴趣的:(Hibernate,jboss,Richfaces,HSQLDB,seam)