Broadleaf Community - SpEL error when using hibernate update instead of create - spring

I am using the community demo site to get familiar with the Broadleaf offering. As a first step, we are trying to prevent the reloading of the database each server start. When I update the hibernate auto properties from 'create' to 'update'
blPU.hibernate.hbm2ddl.auto=update
blEventPU.hibernate.hbm2ddl.auto=update
the server will work (restart) a few times but eventually fail on start with the following error:
2018-11-08 08:51:46.226 ERROR 72159 --- [nio-8443-exec-8] org.thymeleaf.TemplateEngine :
[THYMELEAF][https-jsse-nio-8443-exec-8] Exception processing template "error": Exception evaluating SpringEL expression: "'locale-' + session.blLocale.localeCode" (template: "error" - line 12, col 7)
If I re-run the server with 'create' set, the server will start normally, but we've now lost any data customization.
Any ideas on why the database would need to be 'refreshed' for SpEL to pick up on this locale property?

Related

Error in using HibernateTemplate update method

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.

stomp-chat web socket with embedded tomcat reactor error - type reactor.tuple.Tuple not found

I am having problems getting web socket subscriptions to work properly using Spring with an embedded Tomcat server.
When running this stomp-chat application I get the following error:
org.springframework.messaging.MessageHandlingException: Expression evaluation failed: #chatRoomSessions[headers.simpDestination].add(T(reactor.tuple.Tuple).of(headers.simpSessionId, headers.simpSubscriptionId));
nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1005E:(pos 58): Type cannot be found 'reactor.tuple.Tuple'
I tried to add the following dependency:
compile ("io.projectreactor:reactor-stream:$reactorVersion")
but it gave the same error. Any help would be appreciated.
OK. I see the problem.
The dependency for the io.projectreactor:reactor-stream:2.0.8 isn't enough.
The Tuple class has been moved to the new reactor.fn.tuple package.
So, you still have to fix all the reactor.tuple.Tuple mentioning in the stomp-server.xml to the new reactor.fn.tuple.Tuple.
The sample will be fixed soon: https://github.com/spring-projects/spring-integration-samples/issues/185
Sorry for inconvenience.

Force Spring to always report exceptions as JSON

How do I force Spring to always convert uncaught exception to JSON instead of HTML page?
This is what I get when request is made from Chrome's REST client plugin:
{
timestamp: 1425041457798
status: 404
error: "Not Found"
exception: "com.some.my.Exception"
message: "/rrr does not exist"
path: "/test/rrr"
}
But this is what I get when I access it from browser or from Jersey API (you see parsed HTML):
Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Fri Feb 27 13:37:27 CET 2015There was an unexpected error (type=Not Found, status=404).No message available
I know this can be done somehow by setting the request headers but I want JSON response to be the only variant.
First we need add some exception resolver for exception that trows inside controllers. I prefer extend ResponseEntityExceptionHandler and add own method, but there is a great article on spring.io: http://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
After that if you still get following page you can override org.springframework.boot.autoconfigure.web.ErrorController. There are an example: BasicErrorController. But this works only if you use spring boot application with embedded container. For example, if you will create war file form spring boot project and will deploy under tomcat, you will get standard tomcat error page.
So this mean that ErrorController is not common solution.
In my case i throws exceptions inside filters, that why /error page shown. So solution will be write own filter that converts exceptions to JSON representation. This solution should work for every container/server, and you can get more information about exception.

datanucleus + jpa + oracle. Strange error with tables not existing

I have a strange issue when I try to use Datanucleus to access an Oracle database.
In short, what happens is this :
I run my application; when datanucleus initializes, it complains that it cannot find the tables (although they are in there).
I stop the application, I drop the tables, I add the
datanucleus.autoCreateSchema = true
...property in persistence.xml, and everything works - tables are created and then the select works.
I stop the application again, and then I try to start it with the above parameter disabled.
The error comes back although it was Datanucleus who created the tables in the first place, and now it complains it can't find them.
also please note that the same setup works with a postgresql database behind, without issues.
Can somebody please help ?
A few details about my setup :
I'm using Oracle thin driver.
My entity classes are annotated like this :
#Entity
#Table(name = "tablename1", schema = "schema2000")
Please note that everything works OK if I remove the schema=... from annotation
Error message is :
16:05:40,216 DEBUG [DataNucleus.Connection] - Setting autocommit=false to connection: com.mchange.v2.c3p0.impl.NewProxyConnection#1dff2e1b
16:05:40,216 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection#1dff2e1b" opened with isolation level "read-committed"
16:05:40,904 DEBUG [DataNucleus.Datastore.Schema] - Check of existence of schema2000.tablename1 returned table type of null
16:05:40,905 DEBUG [DataNucleus.Datastore.Schema] - An error occurred while auto-creating schema elements - rolling back
16:05:41,109 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection#1dff2e1b" non enlisted to a transaction is being committed.
16:05:41,110 DEBUG [DataNucleus.Connection] - Connection "com.mchange.v2.c3p0.impl.NewProxyConnection#1dff2e1b" closed
javax.persistence.PersistenceException: Required table missing : "schema2000.tablename1" in Catalog "" Schema "schema2000". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.autoCreateTables"
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:274)
at org.datanucleus.api.jpa.JPAEntityManager.merge(JPAEntityManager.java:519)
Suggest you look closer at case-sensitivity of your identifiers. DataNucleus logs what the JDBC driver allows with a line like
Supported Identifier Cases : "MixedCase" UPPERCASE "MixedCase-Sensitive"
so possibly it requires the schema in UPPERCASE or maybe quoted (all RDBMS are different, and inclusive some differ depending on the operating system they're running on)
Obviously embedding datastore-specific info in annotations is not recommended.

ContextLoader: Context initialization failed

I'm trying to track down the reason why a portion of my application stopped working all of a sudden. I'm running Spring 1 with Weblogic 8.1.4.0 and Hibernate. The report generator is the part that has failed, first on our production server, then on the dev and qa servers on Friday while I was experimenting. I made no changes to the code, but I'm now getting a Missing Data Source exception on the compile statement of a mapping query. The only thing that changed was a couple of records in the database, but they were fairly simple changes that I doubt would have had an impact. I also got the following error from Friday around the time that the two development apps may have failed:
Here is the error in the logs from development server:
04-06 14:31:34 ERROR [main] org.springframework.web.context.ContextLoader: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is javax.naming.LinkException:
And there is a similar one about 10 minutes later from when I deployed to the QA server.
It is referring to a datasource and connection pool defined in WebLogic. I have checked and tested the connection, and there doesn't seem to be any problems with it.
What could possibly be going on that would have caused this? I even reverted back to a build from last week to make sure it was not a code change, but the same datasource required exception occurs:
04-07 16:15:04 DEBUG [ExecuteThread: '14' for queue: 'default'] org.eei.survey.data.RegionDataDAO$NERCRegionMappingQuery: RdbmsOperation with SQL [{call prc_NERCRegions_get}] compiled
04-07 16:15:04 ERROR [ExecuteThread: '14' for queue: 'default'] error.jsp: Error page displayed to user due to unhandled exception
org.springframework.dao.InvalidDataAccessApiUsageException: dataSource is required
at org.springframework.jdbc.object.RdbmsOperation.compile(RdbmsOperation.java:300)
at org.eei.survey.data.ReportDAO$NCRMappingQuery.<init>(ReportDAO.java:535)
at org.eei.survey.data.ReportDAO.executePrcNCR(ReportDAO.java:548)
at org.eei.survey.data.ReportDAO.getNCR(ReportDAO.java:59)
at jsp_servlet._reliability._charts.__barncr._jspService(__barncr.java:235)
Any help would be appreciated.
UPDATE: Here is the full stacktrace of the error:
04-08 14:56:19 WARN [ExecuteThread: '14' for queue: 'default'] org.apache.shale.faces.ShaleViewHandler: No ViewController for viewId /reliability/support/reportgen.faces found under name reliability$support$reportgen
04-08 14:56:19 DEBUG [ExecuteThread: '14' for queue: 'default'] org.eei.survey.data.ReportDAO: java.lang.IllegalArgumentException: No DataSource specified
04-08 14:56:19 ERROR [ExecuteThread: '14' for queue: 'default'] error.jsp: Error page displayed to user due to unhandled exception
java.lang.NullPointerException
at jsp_servlet._reliability._support.__reportgen._jspService(__reportgen.java:156)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:322)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
at org.apache.shale.faces.ShaleViewHandler.renderView(ShaleViewHandler.java:142)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at org.apache.shale.faces.InvokeCommand.execute(InvokeCommand.java:40)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:166)
at org.apache.shale.faces.ShaleApplicationFilter.doFilter(ShaleApplicationFilter.java:218)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at org.eei.survey.web.UserFilter.doFilterInternal(UserFilter.java:30)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6724)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
You are having a problem with the jdni resolution of your datasource. Take a look at the weblogic jdni pool and make usre that you are using the correct name for jdni. java:comp/env/jdbc/reliabilityDS is not working.
This may help:
http://books.google.com/books?id=TiAKHpPHpHIC&pg=PA159&lpg=PA159&dq=weblogic+8.1+jndi+tree&source=bl&ots=cjKNXJZl4o&sig=FHs0YL6hqslNOYjuWpjyRTlCpYY&hl=en&sa=X&ei=veWBT5aVNoTMtgeJ8fC9Bg&ved=0CC0Q6AEwAQ#v=onepage&q=weblogic%208.1%20jndi%20tree&f=false
This also
http://docs.oracle.com/cd/E13222_01/wls/docs81/jndi/jndi.html
This as well
Tomcat vs Weblogic JNDI Lookup
I still don't have a solid answer for why this occurred, but I did figure out how to fix it for now. I basically had to stop my deployed application, then reset the connection pool, then restart again. I would have assumed that restarting the entire server would have accomplished the same thing, but I tried that several times with no results. I don't have hours to track down the source of the problem currently, but if anyone gets into this situation you at least have a quick fix.

Resources