I want to perform CRUD operation using Spring MVC based Hibernate project, so far I have successfully performed add, delete operation. But while updating the data I am getting error show below. I tried adding my primary key to the session and retrieving it along the data to be updated from jsp page. But I am getting error exactly in the line hibernatetemplate.update(emp) line. Where emp is the object to be updated with same primary key as in database. I am using ECLIPSE IDE with Tomcat v9 server.
Servlet.service() for servlet [dispatcher] in context with path [/Demo] threw exception [Request processing failed; nested exception is org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [com.wipro.bean.Employee#254]; nested exception is org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.wipro.bean.Employee#254]] with root cause
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.wipro.bean.Employee#254]
I don't know the logic behind the solution but I used method hibernatetemplate.merge(emp) and it worked.
Related
We have a project using Spring Boot and flyway.
When we run a migration that fails, with logs levels all set to DEBUG, we only got these messages:
[DEBUG] org.flywaydb.core.internal.command.DbValidate - Validating migrations ...
[DEBUG] org.flywaydb.core.internal.scanner.Scanner - Filtering out resource: db/migration/V1/V1_202103081030__account.sql (filename: V1_202103081030__account.sql)
[DEBUG] org.flywaydb.core.internal.scanner.Scanner - Filtering out resource: db/migration/V1/V1_202103081040__place.sql (filename: V1_202103081040__place.sql)
[DEBUG] org.flywaydb.core.internal.scanner.Scanner - Filtering out resource: db/migration/V1/V1_202103151608__document.sql (filename: V1_202103151608__document.sql)
[DEBUG] org.flywaydb.core.Flyway - Memory usage: 147 of 254M
[ERROR] org.springframework.boot.web.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'openEntityManagerInViewInterceptorConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Unsatisfied dependency expressed through method 'openEntityManagerInViewInterceptorConfigurer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openEntityManagerInViewInterceptor' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
...
[INFO ] org.apache.catalina.core.StandardService - Stopping service [Tomcat]
...
Caused by: org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
There is no more details about the reason of the failure (a failing query, an unmatched checksum, ...).
I look at the spring.flyway application properties but found nothing that could be of any help here.
What should we do to display the flyway root error in our logs at server startup?
EDIT: To be clear, the problem is not the failure itself (setting a breakpoint in Flyway classes can reveal the source error). The problem is the missing error details in the logs.
I was having the same problem and found that it was related to the Flyway version I was on (Spring Boot 2.4.3, which uses Flyway 7.1.1). It's a known issue 2987 - Display all validate messages in exceptions, fixed in Flyway 7.2.0.
They recommend running flyway validate -outputType=json as a workaround to get a detailed error message. I tried that, but still didn't get a detailed error message.
The solution that worked for me was upgrading to Flyway 7.2.0, by specifying the version in my pom file:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.2.0</version>
</dependency>
I don't know specifically what is failing, but this might help point you in the right direction.
Open up DbValidate (flyway class). (Download sources if you need to)
Put a break point in the else statement on lines 186-187
Start server again
That will at least tell you which file is failing.
You then might be able to make an enhancement request to the Flyway project for better error reporting.
Well, a lot of things can happen, but one possible reason is that you've changed the migration file after you've applied it already. I'll explain by use case:
Let's say that at time X you have 2 migrations (technically implemented in SQL files): A1 and A2.
This is your first commit with A1 and A2 and when you run the application, flyway creates a special table in the database to see which migrations were already applied. Obviously, there are no migrations there yet at time X so it creates a table, applies A1 and A2, and adds 2 records in the table. These records among other things should include a checksum. Simply put you can think about these checksum as a hash (like sha1) of the content of A1 and A2 correspondingly.
So far so good, now fast forward in time (to time Y) when you introduce a new migration file A3.
When you re-deploy the application, flyway checks that A1 and A2 that have already been applied have not changed, and only after that it applies the new migration.
Now, this validation is really a prerequisite to applying migration A3 checks these hashes - checksums. This is reasonable - because if you happen to have changed A1 or A2 - what should the flyway do - how it can guarantee that migrations work as expected?
You can read also in the official flyway documentation about this validation, however, you get the idea I believe. Someone has changed the checksum by changing one of your existing migrations and have tried to redeploy the applications.
Simply put, Once the migration file has been applied - it can't be changed in a source tree
Now the scenario that I've described is one possible scenario, in general, you don't really have to even create migration A3, it is enough to change the existing migration and try to re-run the application - the validation will fail.
I'm working on a project using Spring Data and MongoDB.
I'm wondering if there is some kind of solution to rollback when some exception (standard or custom) occurs.
I tried this solution but unfortunately it didn't work :
#Transactional(rollbackFor = SomeException.class)
For the moment I'm doing the rollback manually by saving what's already deleted and vis-versa.
NOTE: The exception may occur when contacting a foreign micro-service using http.
NOTE2 : I'm using an Exception handler, I removed it and still not working.
I'm trying to install axis2.jar (1.7) in Websphere 8.5 which is using java 8. I have selected parent last in axis2.jar. Axis2 has some wsdls installed and it'll communicate with oracle 12c to retrieve data. In axis2 shared libraries i'm including xdb6, ojdbc7.jar. When i start to post an xml through SOAP UI, im getting the below error in WAS.
"[7/30/18 11:19:04:368 EEST] 000000b7 IntegrationLa E
'IntegrationLandscapeService' is currently not availble OR does not
exist - RuntimeException : Error creating bean with name
'IntegrationLandscapeServiceImpl' defined in class path resource
[integrationLandscapeServiceContext.xml]: Instantiation of bean
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[com.temenos.services.integrationlandscape.IntegrationLandscapeServiceImpl]:
Constructor threw exception; nested exception is
java.lang.LinkageError: loading constraint violation when overriding
method
"java/sql/SQLXML.getSource(Ljava/lang/Class;)Ljavax/xml/transform/Source;"
during creation of class "oracle/xdb/XMLType": loader
"com/ibm/ws/classloader/CompoundClassLoader#924d5a69" of class
"oracle/xdb/XMLType" and loader
"com/ibm/oti/vm/BootstrapClassLoader#e7afefce" of class
"java/sql/SQLXML" have different types for the method signature"
Oracle.xdb.XMLType is loaded from xdb6.jar and other applications using this xdb6.jar is working fine without issues. But when used from axis2.jar its creating the above error.
Can someone help me or shed some light on this since i couldnt figure out the issue here.
Try to use an isolated class loader. When you configure you shared lib check the "Use an isolated class loader for this shared library".
I am trying to start a deployment of a project to Websphere and I get the following error trail. (Shortened)
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'birtView' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'birtEngine' while setting bean property 'birtEngine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'birtEngine': FactoryBean threw exception on object creation; nested exception is java.lang.RuntimeException: Could not start the Birt engine!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'birtEngine': FactoryBean threw exception on object creation; nested exception is java.lang.RuntimeException: Could not start the Birt engine!
Caused by: java.lang.RuntimeException: Could not start the Birt engine!
Caused by: org.eclipse.birt.core.exception.BirtException: error.CannotStartupOSGIPlatform
Caused by: org.eclipse.birt.core.framework.FrameworkException: Cant register the ExtensionRegistry classpath
Caused by: org.eclipse.core.runtime.CoreException: Extension registry provider is already set.
The solution to the 3rd from bottom error as I have found online was to delete the following line of code.
config.setEngineHome("C:/birt-runtime-3_7_0/ReportEngine");
However, this is not present and unnecessary for our setup.
It(the BIRT specific code used) is very similar to this example online:
http://www.springsource.org/BusinessIntelligenceWithSpringAndBIRT
The BirtView and BirtEngineFactory are the only relevant parts to my project.
I have gone to this Bug Page and forum entry and tried the code addition. It did not work. The project starts up and works on Tomcat 6x without any issue.
http://www.eclipse.org/forums/index.php/m/727929/
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351052
I have the class loader order in Web Sphere set to "Classes loaded with application class loader first." as in the example in the link below.
http://wiki.eclipse.org/BirtPOJO_Viewer_WebSphere_Deployment
I still get the same set of errors and I'm not sure what else I should be doing.
I know it is a bit hard to ask this without posting code, but would someone have an idea as to what I should look for?
Thanks.
I had exactly the same error as yours. I am using BIRT 3.7.2 and IBM WAS 8.5
With reference to the bug detailed below,
org.eclipse.core.runtime.CoreException when restarting the ReportEngine
and the actual reason of the bug, specified below,
ServiceLauncher.shutdown() doesn't release default RegistryProvider
I added the following line before the Platform.startup(..) call
RegistryProviderFactory.releaseDefault();
After this, BIRT reports are working fine.
But, I'm doubtful, as to whether this will break anything in WAS's runtime or not.
The reason for this is ...
As explained in the bug, this exception occurs when Platform start-up is attempted for a second time. Here, on Platform.shutdown(), the RegistryProvider is not released, and hence the exception.
Now, in my case, IBM Websphere 8.5 internally uses OSGi and hence starts OSGi Platform.
Hence, when our application attempts to start the Platform again (the second start), the exception occurs.
My concern here is, this should not break anything with WAS’s runtime (as it uses OSGi internally).
The Registry Provider is not null, as its set by BIRT runtime, so, the only problem here can be of Class Version mismatch i.e., WAS’s Registry Provider and BIRTs Registry Provider, if different, then version clashes.
I'm not sure of the solution i have used.
Experts, please guide.
I've generated my project using Spring Roo and has not touched the xml files.
All I'm trying to do is to get a collection through a ITD method of an entity.
I get the following error:
SEVERE: Servlet.service() for servlet MyProject threw exception
org.hibernate.LazyInitializationException: failed to lazily initialize a collect
ion of role: com.myproject.main.domain.Juser.securityRoles, no session or session
was closed
Please guide me. I'm stuck badly.
Lazy init in hibernate is where it loads relationships on demand instead of at query time.
This is often more efficient as it means the main query is simpler.
Sometimes you need to force the loading of the lazy relp's before the session is closed.
In this case, you just need to call a method on the relp objects just after the query to load them completes.