hibernate - spring 3 + jpa 2 - fully qualified class name in queries -


i've configured spring 3 + jpa 2.0. when do:

em.createquery("from systemuser",systemuser.class).getresultlist(); 

i receive following exception :

java.lang.illegalargumentexception: org.hibernate.hql.ast.querysyntaxexception: systemuser not mapped [from systemuser] @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1201) @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1147) 

but when type qualified class name:

em.createquery("from com.aims.domain.systemuser",systemuser.class).getresultlist(); 

it works. configurations missed out.

my persistence.xml:

<?xml version="1.0" encoding="utf-8"?> <persistence-unit name="aims" transaction-type="resource_local">      <provider>org.hibernate.ejb.hibernatepersistence</provider>     <properties>         <property name="hibernate.dialect" value="org.hibernate.dialect.oracledialect"/>         <!-- value="create" build new database on each run; value="update" modify existing database; value="create-drop" means same "create" drops tables when hibernate closes; value="validate" makes no changes database -->         <property name="hibernate.hbm2ddl.auto" value="validate"/>         <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.defaultnamingstrategy"/>         <property name="hibernate.connection.charset" value="utf-8"/>      </properties> </persistence-unit> 

my appcontext.xml:

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xmlns:context="http://www.springframework.org/schema/context"     xmlns:tx="http://www.springframework.org/schema/tx"     xsi:schemalocation="http://www.springframework.org/schema/beans          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         http://www.springframework.org/schema/context          http://www.springframework.org/schema/context/spring-context-3.0.xsd         http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">       <context:property-placeholder location="classpath*:meta-inf/*.properties" ignore-unresolvable="true" />       <context:annotation-config />      <bean class="org.apache.commons.dbcp.basicdatasource" destroy-method="close" id="datasource">         <property name="driverclassname" value="${database.driverclassname}"/>         <property name="url" value="${database.url}"/>         <property name="username" value="${database.username}"/>         <property name="password" value="${database.password}"/>     </bean>     <bean class="org.springframework.orm.jpa.jpatransactionmanager" id="transactionmanager">         <property name="entitymanagerfactory" ref="entitymanagerfactory"/>      </bean>      <bean id="entitymanagerfactory"         class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean" >         <property name="datasource" ref="datasource"></property>     </bean>      <context:component-scan base-package="com.aims.service" /> </beans>  

for information i'm running test case using junit following annotation:

@runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "classpath*:meta-inf/spring/applicationcontext*.xml" }) @transactionconfiguration(transactionmanager = "transactionmanager", defaultrollback = false) @transactional 

are sure have compiled, resource, persistence.xml jar contains database entities , name of persistence unit (persistenceunitname property spring's localcontainerentitymanagerfactorybean) set properly?

sample persistence.xml (under meta-inf/ in jar contained entities):

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"              xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"              xsi:schemalocation=" http://java.sun.com/xml/ns/persistence     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">   <persistence-unit name="persistenceunit" transaction-type="resource_local"/> </persistence> 

sample spring config:

<bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">     <property name="datasource" ref="datasource"/>     <property name="persistenceunitname" value="persistenceunit"/>     <property name="jpavendoradapter">       <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter"/>     </property> </bean> 

edit: also, named entity: amtb_system_users, query should from amtb_system_users instead of from systemusers

2011-01-25 18:44:02,862 debug [entitybinder] - import entity name amtb_system_users 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -