81606

integrating JPA and SpringIOc

Hi I write small application and trying connect jpa. in my spring configuration file I write this:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver.manager}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.login}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="packagesToScan"> <list> <value>com.epam.newsmanagement.entity</value> </list> </property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="ORACLE" /> </bean> </property> </bean> <bean id="jpaDao" class="com.epam.newsmanagement.dao.JPANewsDao" />

and when I start my application browser giges me 404 error and console give such error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/jpa-configuration.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.jpa.LocalEntityManagerFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

please help)

Answer1:

org.springframework.orm.jpa.LocalEntityManagerFactoryBean does not have a dataSource/ getDataSource() field/method defined. thats why you are getting that exception.

use LocalContainerEntityManagerFactoryBean instead

This may be helps you

Answer2:

In integration of JPA and Spring, If you configure PersistenceUnit in LocalContainerEntityManagerFactoryBean. Make sure to use the same name of PersistenceUnit in persistence.xml and spring-bean.xml. If so, DataSource configuration of LocalEntityManagerFactoryBean may be optional. You might need to configure JpaTransactionManager.

(Assume : jpa-configuration.xml may be spring bean configuraion.)

<strong>Optional :</strong> org.springframework.orm.jpa.vendor.HibernateJpaDialect or com.company.util.HibernateExtendedJpaDialect is used for jpaDialect.

Example : spring-bean.xml

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver.manager}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.login}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <!--<property name="dataSource" ref="dataSource"/>--> <property name="persistenceUnitName" value="your_persistence_unit_name"/> <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/> </property> <!--<property name="jpaPropertyMap"></property>--> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"> </bean> </property> </bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <!-- For MySQL--> <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/> <property name="generateDdl" value="false"/> <property name="showSql" value="true"/> </bean>

Recommend

  • Using Onsen, how to write server side code in NodeJs that will render Jade files as HTML in a splitt
  • What's wrong with my search that doesn't display their marker in google map?
  • VBA Access get string from db
  • Java 8 stream group by min and max
  • Python flask-SQLAlchemy query time out error
  • Android Room Persistence Library - How to find entities with ids contained in list of ids?
  • 100% height child div in parent wrap div
  • Excel VBA Cutting rows from workbook1 and paste it in workbook2
  • auto scan packages for jpa entities in spring
  • SQLite UWP Error with Mobile EMulator Windows 10
  • Spring creating bean but not injecting it
  • How to extract element-path from XMLType Node?
  • Definition of server-class machine changed recently?
  • Oracle: Using CTE with update clause
  • How to automate user interactive command in chef recipe
  • What is the best data type to store boolean values in a database
  • Syncronizing database from Active Directory
  • Integrate two requests into one Javascript
  • cannot load gems in test environment
  • How to set up precision attribute used by @Column annotation?
  • Any command in mysql equivalent to Oracle's autotrace for performance turning
  • Maven use Encrypted passwords in POM
  • Symfony2.1 form date field: Argument 1 passed to … must be an instance of DateTime
  • Implementing Oracle.Web.dll, Oracle.DataAccess.dll 64-bit failed on Windows Server 2008 with IIS 7.5
  • Eloquent Relationship on Partial Match
  • Install phpMongo Drivers on windows
  • How does the HEXTORAW() function work? What is the algorithm?
  • What does certain JVM do after loading ByteCode into memory?
  • Portable JRE on Linux - possible?
  • Do query loads all the data in memory
  • Tomcat memory Leak
  • PLSQL: Get number of records updated vs inserted when a merge statement is used
  • Recording logins for password protected directories
  • How to extract text from Word files using C#?
  • How to check if every primary key value is being referenced as foreign key in another table
  • Sending data from AppleScript to FileMaker records
  • In LanguageTool, how do you create a dictionary and use it for spell checking?
  • How to get NHibernate ISession to cache entity not retrieved by primary key