JPA - Domain Class & Property not found error - java

I'm using Spring boot with a H2 database for local dev work, the problem being encountered is with a domain class that I initially setup. It worked fine but I then renamed a property and now I receive the error "java.lang.IllegalArgumentException: No property name found for type class org.rest.model.Foo"
I think the cause is that the Spring auto configuration has scanned the Domain class but hasn't detected that the property is now different and it's throwing the error.
How can I avoid this from happening as I have a number of changes that I'm implementing as I go?

Related

Using two datasources with Spring Boot

I followed the docs at https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-two-datasources and created my source code accordingly.
When I start up the application I receive this error message:
APPLICATION FAILED TO START
Description:
Failed to configure a DataSource: 'url' attribute is not specified and
no embedded datasource could be configured.
Reason: Failed to determine suitable jdbc url
Action: Consider the following: If you want an embedded database (H2,
HSQL or Derby), please put it on the classpath. If you have database
settings to be loaded from a particular profile you may need to
activate it (no profiles are currently active).
I searched for similar issues and only found that one:
Error access two datasource with Spring Boot
The solution for this was contained in the error message but (at least for me) a little bit too hidden.
I forgot to add the h2 jar so the real reason wasn't that Spring Boot couldn't determine suitable jdbc url but more the missing driver.

Nested variable substitution in spring boot config files

I need to fetch a property with the following format:
${/a/env/mode}
However this depends on where im deployed, I have all the required information in configuration already and is trying to use the following:
${/a/${env}/${mode}}
This is not working as expected in Spring Boot but instead gives an exception. Is there anyway to get what I need?

CGLIB errors converting a weblogic spring web app to springboot app

I am attempting to convert an existing spring weblogic application to a spring boot embedded tomcat application.
There are lots of moving parts so it's hard to show any code, I'm hoping there is some general answer that might clue me in to the issue.
Under weblogic, using the spring-framework 4.3.6.RELEASE libraries, the application deploys fine. It has no problems creating the different service, repository and component beans.
However, when I migrate it to Spring Boot 1.5.1.RELEASE, I get the following error:
2017-06-21 17:08:16,402 [ERROR] SpringApplication reportFailure (815) - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alertEventServiceImpl': Unsatisfied dependency expressed through field 'alertEventDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alertEventDaoImpl' defined in URL [jar:file:/Users/username/Development/source/carma-war/target/carma-war-2.0.0-SNAPSHOT.war!/WEB-INF/lib/protocol-manager-1.8.0-SNAPSHOT.jar!/org/ihc/hwcir/protocol/dao/AlertEventDaoImpl.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.ihc.hwcir.protocol.dao.AlertEventDaoImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class org.ihc.hwcir.protocol.dao.AlertEventDaoImpl
Many of our service classes are final as they shouldn't be extended. Since there are so many that are final, I wanted to minimize the amount of code in our different libraries that we modify to make this work.
I thought because the bean creation process works under weblogic, it should work under spring boot.
Things I have tried to force not using the cglib proxies:
All implementations implement interfaces already
In beans created via xml, added <aop:scoped-proxy proxy-target-class="false"/>
In beans created through annotations, added (example for service bean)
#Service
#Scope(proxyMode = ScopedProxyMode.INTERFACE)
However, in the end, I'm perplexed as to why spring can create beans (the classes marked as final) under the weblogic container but unable to do so under the embedded tomcat spring-boot container.
Spring Boot by default uses class based proxies, which will not work with final classes/methods.
To disable this add spring.aop.proxy-target-class=false to the application.properties to enable JDK Dynamic Proxies instead of class based proxies. (And revert your modifications).
NOTE: To have everything take into account the spring.aop.proxy-target-class you might need to upgrade to Spring Boot 1.5.3 as some final patches where made to include this property in parts that were missed in previous versions.
See the following issues for more information 8434, 8869 and 8887.
I was unable to make this work using M. Deinums' answer using spring.aop.proxy-target-class=false.
What worked for me was to add in the application.properties file
spring.dao.exceptiontranslation.enabled=false
Please note that this option disables proxy creation for repositories.
And in my spring boot application configurer the annotation to handle transactions without using a proxy class.
#EnableTransactionManagement(proxyTargetClass = false)
This is using Spring Boot version 1.5.1.RELEASE.

Cannot determine embedded database driver class for database type NONE

I'm developing an API Server using Spring Boot and Hibernate for persistence.
I created a DataSource in InteliJ and created the entity classes using autogeneration from schema but when i try to run it i get the error :
"Cannot determine embedded database driver class for database type NONE"
even though I provided it in the persistence.xml
In the application.proprieties I didn't write anything.
I tried using methods such as here but I don't use h2Database. In my pom.xml i have the dependency for mysql-connector if that makes a difference.
I analysed this issue for hole day now, I'm out of ideas.
Another thing i tried is : in pom.xml I use h2Database dependecy but when I try to make a query I get this error :
"org.hibernate.tool.hbm2ddl.SchemaExport : Schema "BUY_MEDB" not found; SQL statement:"
I do not know why he's trying to use the BUY_MEDB schema when all my classes are having BuyMeDB schema name. I even tried to use the "INIT=CREATE SCHEMA IF NOT EXISTS BuyMeDB" in persistence.xml and it didn't work.

How to use Spring Data JPA in a simple Servlet?

I'm very new to Spring, but I am working on a project which is using Spring Data JPA to generate repositories for JPA entities.
I'm currently adding a simple module to be able to show some data on a webpage. I have added a Servlet, but I am having trouble accessing the repositories from there.
I have added a ContextLoaderListener in web.xml, I'm referencing the jpa:repositories and persistence.xml in the applicationContext.xml, but I'm currently stuck with this exception:
No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0.
But when I add an EntityManagerFactory in persistence.xml I get the following cryptic message:
java.lang.IllegalAccessError: tried to access field
org.hibernate.engine.spi.CascadeStyle.STYLES from class
org.hibernate.engine.spi.EJB3CascadeStyle
My question is: is what I am trying to do even possible? And if so, how?
Or should I just bite the bullet and use Spring MVC or something else entirely?
Note: this is just for a one-page web site and I'm trying to keep it as simple as possible.
In order to use Spring Data JPA you need to configure the underlying JPA implementation as you would typically do in Spring, see for example, infrastructure.xml and META-INF/persistence.xml in spring-data-jpa-showcase (since Spring 3.1 you can get rid of persistence.xml if you use packagesToScan property of LocalContainerEntityManagerFactoryBean).
Your second problem with IllegalAccessError looks like a classloading problem caused by presence of different versions of Hibernate jars in classpath.

Categories

Resources