This Spring transaction Manager is always not active
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I use spring 5 and hibernate 5, tomcat, session factory for transaction by program and/or xml. It seems no active transaction. It seems @Transactional is useless. I even print configured transaction manager inside AppConfig, still false, even though transaction Manager is not null:
Please help!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I don't normally configure Spring Data in Java code. I just use the application.xml bean definition file for that.
I get the impression that you are trying to use Spring Data on Legacy Hibernate and I'm not sure that there is support for that. @Transactional works just fine on Spring Data JPA using Hibernate JPA as the JPA provider, though.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It was working with Hibernate Session and @Transactional use xml configuration in the past. I upgraded Spring 3 to 5, struts from 1.2 to 2, also log4j to log4j2.
A. W.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I tried all, it's just no transaction, I even did it inside AppConfig for Hibernate transaction manager, it seems fine and proxy, return a valid transaction manaer but its not active t all, no way to make it.
A. W.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Here's how I configure my persistence, which, as I said, I do in XML and not in Java code. The JDBC connection options come from JNDI.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have about 100 of them if use begin/commit for each.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You'd be better off upgrading the legacy Hibernate code (using Sessions) to Hibernate JPA (using EntityManager).
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If I configure it use JPA Transaction Manager, am I still able to use Hibernate Session (Open/Current) to session.getNamedQuery ?
A.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I actually don't see anything wrong in the configuration. Could get the Configuration bean or any @Bean include transaction manager. How come SpringSynchronizationManager/@Transactional never active? There should be a way to active/deactivate it on the fly rather than just @EnableTransactionManagement.
A.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Legacy Hibernate and Hibernate JPA are like Java and JavaScript. Just because they look a lot alike doesn't mean you can put Java code in a JavaScript file and expect it to work no matter how well you think you've configured it.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hibernate JPA does NOT use sessions. At all. Ever, That's only for legacy Hibernate. And you really shouldn't be using legacy Hibernate if you want Spring Data.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Also, all entities/beans need to be registered?
Failed to initialize JPA EntityManagerFactory: No identifier specified for entity: com.core.user.bean.User
Thanks!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When you use Spring Data JPA, you can provide a package path that JPA uses to scan for @Entity classes and automatically registers them. For example, I typically define my JPA Entities as classes under a path such as com.mousetech.myapp.persistence.
I don't have enough context to guess at what your third question requires. Although it might happen if User wasn't a registered Entity.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yes, you can use Struts. Or JavaServerFaces, Or Spring Web. Or pretty much any other JEE-compatible web MVC framework. I don't recommend Struts anymore, but that's just because Struts is kind of awkward compared to the more modern MVC frameworks.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I put all on class path, it keeps complaint about a custom type:
Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Unable to instantiate custom type:com.platform.GenericEnumUserType
I've a lot of int in database that use enumerations, it seems each needs to convert, so troublesome!
Thanks,
A.W.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You still have legacy Hibernate polluting your app. As I said before, Hibernate JPA does not have "Session". Any reference to "Session" when using Hibernate JPA means that your application is improperly set up.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Also, <generator class="identity"/> in xml should map to @Generated ?
Happy New Year!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Use @Transient for fields in an Entity that don't map to database columns. Generally, don't define @Transient properties at all. Keep that data somewhere else.
The @GeneratedValue annotation allows you to mark a column as being auto-generated and to select what value generation algorithm will be used to generate those values.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
1. Should I change all dao and bean to use repository and JPA CRUD?
2. Also, if I use more than one @Configuration file, do I need to initialize/register all?
3. Does authentication processUrl is default, no use or same as home / in Spring Security Configuration since Spring loadUserbyname handles it?
Thanks,
A
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
2. "@Configuration" isn't a file, it's an annotation used to assist the framework in configuring the app. You can have many files containing @Configuration. All that's required is to let Spring know where to find them so that it can limit its package scans to the appropriate places and not waste a lot of time scanning every class in the app.
Now if you meant "application configuration" such as "application.properties", you can have multiple application configuration files in both property and YAML form, The Spring documentation has a long list of where it looks for application properties and the order it reads tham in. Which is important, since Spring has rules to determine which property value to use if the same property is defined in more than one location.
I'm not sure what you are referring to, but it sounds like part of Spring Security. Which I have gotten a lot more familiar with in the last week or two.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am confused as let Spring know where to find them so that it can limit its package scans to the appropriate places , like this:
@Configuration
@Import({AppConfig.class, SecurityConfig.class, PersistenceJPAConfig.class})
public class AppInitializer implements WebApplicationInitializer {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppInitializer.class);
//must call ctx.refresh() before you can call or use the above for ctx.getBean(HelloWorld.class);
logger.error("AppInitializer getBean name:" + ctx.containsBean("SecurityConfig"));
//OMG!
root.register(SecurityConfig.class);
//root.register(AppConfig.class);
//root.register(PersistenceJPAConfig.class);
//root.register(AppConfig.class);
sc.addListener(new ContextLoaderListener(root));
root.refresh(); //AbstractApplicationContext is subclass, can also call refresh()
//logger.error("In AppInitializer getJPAConfig: " + ctx.getBean(PersistenceJPAConfig.class));
logger.error("In AppInitializer getSecurityConfig: " + ctx.getBean(SecurityConfig.class));
//logger.error("In AppInitializer getSession Factory: " + ctx.getBean(SessionFactory.class));
sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")) //already added FilterChain
.addMappingForUrlPatterns(null, false, "/*");
Also, componentScan, I've libraries in a jar file with different folders not in current configuration files
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'm not sure what your code fragment is supposed to represent, but here's all I need to set up a webapp with JPA in Spring Boot:
A Spring webapp not using Spring Boot would be a little different, and Spring Security is handled in its own @Configure'd file, but it's all pretty simple for the developer, if a bit magic.
Note that there are two scans defined here in the main class. @EntityScan tells JPA what the package path is to scan for JPA Entity classes. @ServletComponentScan has no path value, so the scan is done relative to the current (main class) package.
This might be a good article to read: https://www.baeldung.com/spring-component-scanning
Finally, be careful when chasing documentation about Spring's web, security and JPA services. Some of this stuff has evolved a lot, but the Internet is a great place to find stale information. Fortunately, Spring is fairly good about backwards compatibility if you fail to use the latest and greatest config stuff.
Signs that you've got recent docs are that the examples are usually POJO-based with no "extends" or "implements" requirements for your Spring class, use of annotations, and lambda notation in place of chained method invocations.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I hate to reuse the tread, just be easier for this one:
---------------------------------
Exception
org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL contained a potentially malicious String "//"
org.springframework.security.web.firewall.StrictHttpFirewall.rejectedBlacklistedUrls(StrictHttpFirewall.java:374)
org.springframework.security.web.firewall.StrictHttpFirewall.getFirewalledRequest(StrictHttpFirewall.java:336)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:194)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267)
---------------------------------------
I try to add cors, in vain no matter what, it does not have any constructor-ar nor property or factory:
<beans:bean id="corsSource" class="org.springframework.web.cors.UrlBasedCorsConfigurationSource">
<!--beans:constructor-arg name="corsConfiuration">
<beans:bean class="org.springframework.web.cors.CorsConfiguration">
<beans:property name="allowedOrigins" value="*" />
<beans:property name="allowedMethods" value="*" />
<beans:property name="allowedHeaders" value="*" />
<beans:property name="allowCredentials" value="true" />
</beans:bean>
</beans:constructor-arg-->
</beans:bean>
Thanks ahead!
A.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I've that in java configuration files, not sure which one worked. Is there a way to add it/switching to XML configuration since Spring (not boot) does not read configuration/scan component easily.
Thanks,
A.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Java configuration always complaint about Exception:Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'SecurityConfig': Unsatisfied dependency expressed through field 'httpSecurity'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Anyone around can help?
| You know it is dark times when the trees riot. I think this tiny ad is their leader: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








