<persistence-unit name="myEntityManager" transaction-type="RESOURCE_LOCAL"> <class>com.epam.testapp.model.News</class> <exclude-unlisted-classes>true</exclude-unlisted-classes>


private Integer newsId; private String title; private String brief; private String content; private Date created; private String dateCreatedString; public News() { } @Id @Column(name = "NEWS_ID") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "news_seq") @SequenceGenerator(name = "news_seq", sequenceName = "NEWS_SEQ") public Integer getNewsId() { return newsId; } public void setNewsId(Integer newsId) { this.newsId = newsId; } @Column(nullable = false, name = "TITLE") public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @Column(nullable = false, name = "BRIEF") public String getBrief() { return brief; } public void setBrief(String brief) { this.brief = brief; } @Column(name = "CONTENT") public String getContent() { return content; } public void setContent(String content) { this.content = content; } @Temporal(value = TemporalType.DATE) @Column(nullable = false, name = "CREATED") public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } @Transient public String getDateCreatedString() { return dateCreatedString; } public void setDateCreatedString(String dateCreatedString) { this.dateCreatedString = dateCreatedString; }

equals and hashcode

xml for spring

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="/WEB-INF/databaseConfiguration.properties"/> </bean> <bean id="newsDAO" class="com.epam.testapp.database.NewsDaoJPA"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="entityManagerFactory" class= "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"> <property name="showSql" value="true"/> <property name="database" value="ORACLE"/> </bean> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${database.driver}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.user}"/> <property name="password" value="${database.password}"/> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> <property name="dataSource" ref="dataSource"/> </bean>

but when call dao method for example

public List<News> getList() throws DAOException { return getJpaTemplate().find("select n from News n"); }

i get

java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:423) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:485) at $Proxy4.createEntityManager(Unknown Source) at org.springframework.orm.jpa.EntityManagerFactoryAccessor.createEntityManager(EntityManagerFactoryAccessor.java:116) at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:176) at org.springframework.orm.jpa.JpaTemplate.contains(JpaTemplate.java:245) at com.epam.testapp.database.NewsDaoJPA.getList(NewsDaoJPA.java:26) at com.epam.testapp.presentation.action.NewsAction.list(NewsAction.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:146) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.epam.testapp.utils.filter.EncodingFilter.doFilter(EncodingFilter.java:45) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)

Have some idea?

-------------Problems Reply------------

Your loadTimeWeaver is a SimpleLoadTimeWeaver, which is usually used in testing environments. From the javadocs

LoadTimeWeaver that builds and exposes a SimpleInstrumentableClassLoader.

Mainly intended for testing environments, where it is sufficient to perform all class transformation on a newly created ClassLoader instance.

According to this entry in the manual on Spring JPA I suspect you'll need something more like this:

<bean id="entityManagerFactory"
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="database" value="ORACLE"/>

and you according to this may have to modify the tomcat context to tell tomcat to use a custom classloader:

<Context path="/myWebApp" docBase="/my/webApp/location">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>

Category:spring Views:1 Time:2011-08-18

Related post

  • Transactions Not Starting using Spring and JPA in Tomcat 2012-03-21

    I'm attempting to use JPA with Spring inside tomcat and having problems where transactions are not being started as expected. I'm using Hibernate 3.6.9.Final, Spring 3.0.5.RELEASE and running in Tomcat 6.0.30. I have a separate data access jar that c

  • Spring JPA: Testing DAO layer with multiple databases in a CI environment 2012-02-21

    We are working on a project where database requirement is not clear. So we are building a database agnostic application. See my previous question here: Database Agnostic Application Now I want to test my Spring application DAO with multiple database.

  • flex blazeds spring jpa hibernate under eclipse project 2011-05-06

    I'm looking for a tutorial where the following technologies: flex blazeds spring jpa hibernate are use into eclipse to create a Java EE web dynamic project. I wish that the jpa and hibernate will be auto-generated by an orm plugin (such as hibernate

  • Configuring Spring/JPA Hibernate on Eclipse 2011-05-26

    I have been fighting for days to install Spring 3.1(latest) and Hibernate JPA on my system. I went through all the tutorial but have not been able to fix it. I've already installed Spring from Eclipse's Install New Software. I now want to add Hiberna

  • Spring + JPA + MVC - Error creating bean 2012-02-06

    I developed a Spring JPA project in eclipse wich access to the data stored in a mysql server. Now I need to import this project in a Spring @ MVC project. So I configure in the build path of the JPA project to export the maven dependencies I added th

  • DWR + Spring + JPA Session Closed 2009-10-14

    Background The application I am working on currently uses Spring + JPA. Everything was working fine before we decided to introduce DWR. Using DWR I invoke a method on a Service class and it then redirects to the Controller. try{ return WebContextFact

  • JPA DAO integration test not throwing exception when duplicate object saved? 2010-06-14

    I am in the process of unit testing a DAO built with Spring/JPA and Hibernate as the provider. Prior to running the test, DBUnit inserted a User record with username "poweruser" -- username is the primary key in the users table. Here is the integrati

  • How to pass around JDBC connection without using Spring/JPA/Hibernate 2010-12-09

    We have a Java J2EE application that was using individual web service calls for each database row insert/update. That turned out to be WAY too slow. They have brought me in to "quickly" fix it. I plan to convert all the web service calls to plain JDB

  • Spring+JPA Netbeans deployment problem 2011-03-11

    Greetings, I have a web application that uses spring and JPA. logs tell me everything is running fine. However, I used Netbeans to create this application and so am using it for deployment on the server too. During deployment I get this error: Starti

  • Using transaction in Spring 3.0 in Spring + JPA + Hibernate 2011-05-10

    I currently using Spring + JPA + hibernate in a project. Then i decide my design pattern in model dan DAO implementation. I have a abstract for all my transaction purpose class. Every class( as a service) that perform a single update/create/delete ta

  • Spring / JPA / Hibernate / PostgreSQL throws EntityNotFoundException in nested transaction 2011-06-01

    I have the following setup: Spring -> JPA -> Hibernate -> PostgreSQL I've created a service layer which offers some "@Transactional" methods to insert data. The data is in the concrete case a person entity which has to be connected to a cate

  • Spring, JPA, glassfish, EAR, TransactionRequiredException 2011-12-15

    After nearly 10 hours of searching and trying different things I couldn't figure out, what is main cause of my problem. So, maybe someone could help me here. I'm learning Spring + JPA. I have EAR project (in Eclipse) consist of two projects: JPA and

  • Spring JPA entities not saving to database 2012-02-15

    I am facing some issues in Spring JPA. I successfully configured the Spring JPA project and am able to run the project without having any exception. I intension to save the entities to the database. But when I am running the project, it is neither sa

  • Spring JPA/HIbernate create/update views when the application starts 2012-03-02

    Our application is based on spring, JPA, Hibernate (3.5.1), postgresql 8.4 We will deliver a new .war file to our clients, but we have quite a few new views in the DB needed to be created before they can run some reports. I tried to put an import.sql

  • Using Spring managed DAO without controller? 2009-11-25

    I'm trying to get my Portlets work with some DAO Objects which I configured as spring beans. I've included an application.xml to my WEB-INF, added it to my web.xml, configured hibernater support, a datasource. Everything seems fine, after deployment

  • "Access is denied" message while deploying spring app in tomcat 6 2010-02-16

    While trying to deploy my spring app on tomcat 6 I get an error saying java.util.logging.errormanager:4 java.io.filenotfoundexception: c:\program files\apache software foundation\tomcat 6.0\logs\catalina.2010.02.16.log <Access is denied> at jav

  • Is solr a web application that can run on the same instance as a spring app on tomcat? 2010-03-09

    Is solr a web application that can run on the same instance as a spring app on tomcat? I've always run solr on its own server (jetty), along with a asp.net app so a bit confused if you need solr to run on its own server. Or can you run both a spring

  • Spring+JPA+Hibernate+Oracle insert query showing but data not inserting into DB 2010-08-28

    Help to solve this issue: Spring+JPA+Hibernate+Oracle insert query showing but data not inserting into DB : One to One relationship, here query for One table is showing second table insert query not showing, also data not inserting into DB.

  • Wicket+Spring+JPA+Hibernate: No Persistence Unit Found 2010-10-06

    I'm developing a web application using Wicket+Spring+JPA+Hibernate. This is my first project with this setup and I think I've probably made some mistakes. I get the following error: No persistence unit called "ApplicationEntityManager" found. My pers

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.162 (s). 11 q(s)