Fix JPA load.

This commit is contained in:
Paulo Gustavo Veiga 2024-01-13 18:31:21 -08:00
parent e1b517f657
commit fbbc95fd59
4 changed files with 35 additions and 12 deletions

View File

@ -20,10 +20,13 @@ public class Application {
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder() new SpringApplicationBuilder()
.parent(Application.class, MethodSecurityConfig.class).web(WebApplicationType.NONE) .parent(Application.class, MethodSecurityConfig.class, HibernateConfig.class).web(WebApplicationType.NONE)
.child(MvcAppConfig.class, MvcSecurityConfig.class, HibernateConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET) .child(MvcAppConfig.class, MvcSecurityConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET)
// .sibling(RestAppConfig.class).web(WebApplicationType.SERVLET) .sibling(RestAppConfig.class).web(WebApplicationType.SERVLET)
.run(args); .run(args);
// new SpringApplicationBuilder(Application.class, MethodSecurityConfig.class,MvcAppConfig.class, MvcSecurityConfig.class, HibernateConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET).run(args);
} }
@Bean @Bean

View File

@ -1,12 +1,22 @@
package com.wisemapping.config; package com.wisemapping.config;
import com.wisemapping.model.User;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories("com.wisemapping.model")
@Configuration @Configuration
@EnableTransactionManagement @EnableAutoConfiguration
@EnableJpaRepositories("com.wisemapping.model") @EnableJpaRepositories(basePackages={"com.wisemapping.dao"})
@EntityScan(basePackageClasses= User.class)
public class HibernateConfig { public class HibernateConfig {
// @Bean // @Bean

View File

@ -21,8 +21,9 @@ package com.wisemapping.dao;
import com.wisemapping.model.*; import com.wisemapping.model.*;
import com.wisemapping.security.DefaultPasswordEncoderFactories; import com.wisemapping.security.DefaultPasswordEncoderFactories;
import com.wisemapping.security.LegacyPasswordEncoder; import com.wisemapping.security.LegacyPasswordEncoder;
import jakarta.annotation.Resource; import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.TypedQuery;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
@ -43,15 +44,20 @@ public class UserManagerImpl
@Autowired @Autowired
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
@Autowired
private EntityManager entityManager;
@Autowired @Autowired
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
public UserManagerImpl() {
}
public void setEncoder(PasswordEncoder passwordEncoder) { public void setEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
} }
public List<User> getAllUsers() { public List<User> getAllUsers() {
return getSession().createSelectionQuery("from com.wisemapping.model.User user", User.class).getResultList(); return entityManager.createQuery("from com.wisemapping.model.User user", User.class).getResultList();
} }
private Session getSession() { private Session getSession() {
@ -64,7 +70,7 @@ public class UserManagerImpl
public User getUserBy(@NotNull final String email) { public User getUserBy(@NotNull final String email) {
User user = null; User user = null;
SelectionQuery<User> query = getSession().createSelectionQuery("from com.wisemapping.model.User colaborator where email=:email",User.class); TypedQuery<User> query = entityManager.createQuery("from com.wisemapping.model.User colaborator where email=:email",User.class);
query.setParameter("email", email); query.setParameter("email", email);
final List<User> users = query.getResultList(); final List<User> users = query.getResultList();

View File

@ -3,15 +3,19 @@ Springboot Common
################################################################################## ##################################################################################
spring.datasource.initialize=true spring.datasource.initialize=true
spring.jpa.open-in-view=true
#spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.sql.init.mode=always
spring.main.allow-circular-references=true spring.main.allow-circular-references=true
spring.jpa.open-in-view=true
spring.jpa.properties.hibernate.current_session_context_class=thread spring.jpa.properties.hibernate.current_session_context_class=thread
spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.format_sql=true
spring.sql.init.mode=always
logging.level.root=TRACE ##################################################################################
Log Level
##################################################################################
logging.level.root=INFO
logging.level.org.apache.tomcat=INFO
################################################################################## ##################################################################################
# Mail configuration. Must be configured to enable user registration confirmation. # Mail configuration. Must be configured to enable user registration confirmation.