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) {
new SpringApplicationBuilder()
.parent(Application.class, MethodSecurityConfig.class).web(WebApplicationType.NONE)
.child(MvcAppConfig.class, MvcSecurityConfig.class, HibernateConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET)
// .sibling(RestAppConfig.class).web(WebApplicationType.SERVLET)
.parent(Application.class, MethodSecurityConfig.class, HibernateConfig.class).web(WebApplicationType.NONE)
.child(MvcAppConfig.class, MvcSecurityConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET)
.sibling(RestAppConfig.class).web(WebApplicationType.SERVLET)
.run(args);
// new SpringApplicationBuilder(Application.class, MethodSecurityConfig.class,MvcAppConfig.class, MvcSecurityConfig.class, HibernateConfig.class, ServletConfig.class).web(WebApplicationType.SERVLET).run(args);
}
@Bean

View File

@ -1,12 +1,22 @@
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.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories("com.wisemapping.model")
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories("com.wisemapping.model")
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages={"com.wisemapping.dao"})
@EntityScan(basePackageClasses= User.class)
public class HibernateConfig {
// @Bean

View File

@ -21,8 +21,9 @@ package com.wisemapping.dao;
import com.wisemapping.model.*;
import com.wisemapping.security.DefaultPasswordEncoderFactories;
import com.wisemapping.security.LegacyPasswordEncoder;
import jakarta.annotation.Resource;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.TypedQuery;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@ -43,15 +44,20 @@ public class UserManagerImpl
@Autowired
private EntityManagerFactory entityManagerFactory;
@Autowired
private EntityManager entityManager;
@Autowired
private PasswordEncoder passwordEncoder;
public UserManagerImpl() {
}
public void setEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}
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() {
@ -64,7 +70,7 @@ public class UserManagerImpl
public User getUserBy(@NotNull final String email) {
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);
final List<User> users = query.getResultList();

View File

@ -3,15 +3,19 @@ Springboot Common
##################################################################################
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.jpa.open-in-view=true
spring.jpa.properties.hibernate.current_session_context_class=thread
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.