Hi EveryOne my name is Vicente
Im new to Spring and Im doing my first Spring Based app, but Im not able to make it work so PLEASE Help im kind of fustrated by now
the error:
Code:Im not able to get an entitymanager via jndi-lookup it returns a null value
the code
DAO:
Code:public class testDao{ @PersistenceContext private EntityManager em; //GETTERS AND SETTERS public void test() { if(em==null){ System.out.println("NULL"); }else{ System.out.println("NOT NULL"); } } }
applicationContext.xml:
web.xmlCode:<?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:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"> <jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/bookstorePU"/> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <bean id="testDao" class="com.vicente.app.dao.testDao" /> </beans>
persistence.xml:Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Bookstore</display-name> <description>Bookstore example</description> <context-param> <description>Spring configuration file</description> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <description>Spring Loader</description> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <persistence-unit-ref> <persistence-unit-ref-name>persistence/bookstorePU</persistence-unit-ref-name> <persistence-unit-name>bookstorePU</persistence-unit-name> </persistence-unit-ref> </web-app>
pom.xml (SPRING VERSION 2.5.6)Code:<persistence 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" version="1.0"> <persistence-unit name="bookstorePU" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/bookstore</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="validate"/> <property name="hibernate.connection.datasource" value="jdbc/bookstore"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/> <property name="hibernate.default_batch_fetch_size" value="20"/> </properties> </persistence-unit> </persistence>
OTHER INFOCode:<!-- HIBERNATE --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>${hibernate-entitymanager-version}</version> <type>jar</type> <scope>compile</scope> </dependency> <!-- SPRING --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>${spring-version}</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring-version}</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring-version}</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-dao</artifactId> <version>${spring-version-dao}</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring-version}</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws</artifactId> <version>${spring-version-ws}</version> <type>pom</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring-version}</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jpa</artifactId> <version>${spring-version-jpa}</version> <type>jar</type> </dependency> <!-- JAVA EE --> <dependency> <groupId>javaee</groupId> <artifactId>javaee-api</artifactId> <version>5</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j-version}</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>${commons-dbcp-version}</version> <type>jar</type> </dependency>
-I have configured a JDBC resource in glassfish named jdbc/bookstore
PLEASEEE help![]()



Reply With Quote
