Why Hibernate throws "no identifier specified"? - java

I'm trying to insert data into an Oracle database for which I have attached the screenshot of it. There is an entity class created inside a model package which contains all columns and a table. There is an id column which is auto-increment in the database details attached. The main issue is with auto incremented data for id column using #GeneratedValue(strategy = GenerationType.IDENTITY) which gives me no identity specified for this entity details of error attached below. So for this created an object of that entity class and using save method I was trying to save the same but due to error for that identifier, it is not getting saved.
This is my entity class which contains tables and columns
package com.sid.demo.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
//import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.springframework.data.annotation.Id;
#Table(name="user_registration") //this is a table present in my oracle database
#Entity
public class hindalco_model
{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY) //this is where problem exists
#Column(name="user_id",updatable=false,nullable=false)
private Long user_id; //this is column a present in oracle database which is auto incremented
#Column(name="user_name")
private String user_name;
#Column(name="email")
private String email;
#Column(name="password")
private String password;
public Long getUser_id() {
return user_id;
}
public void setUser_id(Long user_id) {
this.user_id = user_id;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
#Override
public String toString() {
return "hindalco_model [user_id=" + user_id + ", user_name=" + user_name + ", email=" + email + ", password="
+ password + "]";
}
}
This is my controller class in which I have created an object of the above entity class
package com.sid.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.sid.demo.model.hindalco_model;
import com.sid.demo.repository.hindalco_repository;
#RestController
#RequestMapping("/hindalco_user")
public class hindalco_controller
{
#Autowired
hindalco_repository hindalco_repo;
#RequestMapping(value="/user_registration",method = RequestMethod.GET, produces = {"application/json"})
public hindalco_model user_registration(hindalco_model hindalco)
{
hindalco_repo.save(hindalco);
return hindalco;
}
}
//this is my repository class through which I am calling save method which takes entity class object as an argument
package com.sid.demo.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.sid.demo.model.hindalco_model;
public interface hindalco_repository extends JpaRepository<hindalco_model,Integer>
{
}
//below is my database SQL query which I have executed for auto increment. First I have created a sequence below in commented line and then trigger for the auto incremented
/*create sequence friend_auto start with 1 increment by 1;*/
create or replace trigger user_id
before insert on user_registration
for each row
begin
:new.user_id :=user_id.nextval;
end;
Attached the database screenshot details of all columns
enter image description here
Below are the errors that are getting generated while compilation
2019-02-27 18:30:09.076 INFO 7412 --- [ main] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2019-02-27 18:30:09.079 INFO 7412 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-02-27 18:30:09.080 INFO 7412 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1603 ms
2019-02-27 18:30:09.293 INFO 7412 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-02-27 18:30:09.295 WARN 7412 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
2019-02-27 18:30:09.463 INFO 7412 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-02-27 18:30:09.529 INFO 7412 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-02-27 18:30:09.700 INFO 7412 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.0.Final}
2019-02-27 18:30:09.701 INFO 7412 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-02-27 18:30:09.850 INFO 7412 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-02-27 18:30:10.037 INFO 7412 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
2019-02-27 18:30:10.254 INFO 7412 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [byte[]] overrides previous : org.hibernate.type.BinaryType#59696551
2019-02-27 18:30:10.254 INFO 7412 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [[B] overrides previous : org.hibernate.type.BinaryType#59696551
2019-02-27 18:30:10.255 INFO 7412 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [Byte[]] overrides previous : org.hibernate.type.WrapperBinaryType#17273273
2019-02-27 18:30:10.255 INFO 7412 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [[Ljava.lang.Byte;] overrides previous : org.hibernate.type.WrapperBinaryType#17273273
2019-02-27 18:30:10.313 WARN 7412 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.sid.demo.model.hindalco_model
2019-02-27 18:30:10.313 INFO 7412 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-02-27 18:30:10.327 INFO 7412 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2019-02-27 18:30:10.330 INFO 7412 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-02-27 18:30:10.345 INFO 7412 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-27 18:30:10.355 ERROR 7412 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.sid.demo.model.hindalco_model
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at com.sid.demo.SpringBootJpaApplication.main(SpringBootJpaApplication.java:10) [classes/:na]
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.sid.demo.model.hindalco_model
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:785) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:903) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:934) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
... 16 common frames omitted
The exact error below one
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.sid.demo.model.hindalco_model

In hindalco_model you annotated user_id with org.springframework.data.annotation.Id, but it should be javax.persistance.Id.
Change the import at line 9 with
import javax.persistance.Id;
Also be aware that you defined your monel id tye as Long, while in your hindalco_repository you set it as Integer.
Change JpaRepository<hindalco_model,Integer> to JpaRepository<hindalco_model, Long>

Related

I'm trying to create custom login page with userName and Password Stored in database.but i cannot resolve this error

I'm a beginner for spring security, the code looks fine and I think something is missing.
while hoisting the app it will show the following error, but I have nowhere created the bean for appconfig
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
2020-03-14 12:31:34.584 INFO 5148 --- [ main] com.access6.SecureDemoAppApplication : Starting SecureDemoAppApplication on DESKTOP-G23R8VK with PID 5148 (D:\workspace-spring-tool-suite-4-4.5.1.RELEASE\SecureDemoApp\target\classes started by Admin in D:\workspace-spring-tool-suite-4-4.5.1.RELEASE\SecureDemoApp)
2020-03-14 12:31:34.588 INFO 5148 --- [ main] com.access6.SecureDemoAppApplication : No active profile set, falling back to default profiles: default
2020-03-14 12:31:35.199 INFO 5148 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-14 12:31:35.255 INFO 5148 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 49ms. Found 1 JPA repository interfaces.
2020-03-14 12:31:35.717 INFO 5148 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-14 12:31:35.724 INFO 5148 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-14 12:31:35.724 INFO 5148 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-14 12:31:35.918 INFO 5148 --- [ main] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2020-03-14 12:31:35.922 INFO 5148 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-14 12:31:35.922 INFO 5148 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1291 ms
2020-03-14 12:31:36.075 INFO 5148 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-03-14 12:31:36.133 INFO 5148 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-03-14 12:31:36.258 INFO 5148 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-14 12:31:36.451 INFO 5148 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-14 12:31:36.838 INFO 5148 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-03-14 12:31:36.854 INFO 5148 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-03-14 12:31:37.401 INFO 5148 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-03-14 12:31:37.408 INFO 5148 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-14 12:31:37.467 WARN 5148 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-14 12:31:37.710 WARN 5148 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appConfig': Unsatisfied dependency expressed through field 'UserDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'reop'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.access6.User com.access6.UserRepo.findByUserName(java.lang.String)! No property userName found for type User!
2020-03-14 12:31:37.710 INFO 5148 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-03-14 12:31:37.713 INFO 5148 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-03-14 12:31:37.718 INFO 5148 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-03-14 12:31:37.720 INFO 5148 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-03-14 12:31:37.734 INFO 5148 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-14 12:31:37.743 ERROR 5148 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appConfig': Unsatisfied dependency expressed through field 'UserDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'reop'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.access6.User com.access6.UserRepo.findByUserName(java.lang.String)! No property userName found for type User!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
Here is my code:
Configuration class
package com.access6;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
#SuppressWarnings("deprecation")
#Configuration
#EnableWebSecurity
public class AppConfig extends WebSecurityConfigurerAdapter {
#Autowired
public UserDetailsService UserDetailsService;
#Bean
public AuthenticationProvider authpro() {
DaoAuthenticationProvider DAuthpro= new DaoAuthenticationProvider();
DAuthpro.setUserDetailsService(UserDetailsService);
DAuthpro.setPasswordEncoder(NoOpPasswordEncoder.getInstance());
return DAuthpro;
}
#Bean
public User u () {
return new User();
}
}
controller class
package com.access6;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
#RestController
public class SecureContrlr {
#RequestMapping("/")
public ModelAndView weclome() {
return new ModelAndView("home");
}
}
Model
package com.access6;
import javax.persistence.Entity;
import javax.persistence.Id;
#Entity
public class User {
#Id
private int id;
private String name;
private String password;
//getters and setters
}
Repository
package com.access6;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.stereotype.Repository;
#Repository
#EnableJpaRepositories
public interface UserRepo extends JpaRepository<User, Long> {
User findByUserName(String UserName);
}
Service class-something is wrong in this class but I cannot identify the problem here
package com.access6;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
#Service
public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {
#Autowired
private UserRepo reop;
#Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user=reop.findByUserName(username);
if(user==null) {
throw new UsernameNotFoundException("404 user");
}
return new UserDetailsImpli(user);
}
}
implementation class
package com.access6;
import java.util.Collection;
import java.util.Collections;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
#Service
#Component
#SuppressWarnings("serial")
public class UserDetailsImpli implements UserDetails {
User user;
public UserDetailsImpli(User user) {
super();
this.user = user;
}
#Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Collections.singleton(new SimpleGrantedAuthority("USER"));
}
#Override
public String getPassword() {
// TODO Auto-generated method stub
return user.getPassword();
}
#Override
public String getUsername() {
// TODO Auto-generated method stub
return user.getName();
}
#Override
public boolean isAccountNonExpired() {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean isAccountNonLocked() {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean isCredentialsNonExpired() {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean isEnabled() {
// TODO Auto-generated method stub
return true;
}
}
Your custom repository method is wrong. Change to:
User findByName(String name);
Just as the exception tells you
No property userName found for type User!
The findBy* only works if name it exactly like in your model.
Update
First you can Google what a UnsatisfiedDependencyException means. Now you can read the message. This can be a bit tricky, because as in this case there can be nested exections, with difficult to read messages in one line.
Let's break it down.
This is the beginning, telling you there was a problem when creating your UserDetailsServive bean:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appConfig': Unsatisfied dependency expressed through field 'UserDetailsService';
But the problem wasn't the service but your Repository bean:
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'reop';
Inside the Repository bean the creation of a method failed for some reason:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepo': Invocation of init method failed;
And there it is: spring tries to create a method findByUserName, but the User model doesn't have a property named userName:
nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.access6.User com.access6.UserRepo.findByUserName(java.lang.String)! No property userName found for type User!
Reading an exception like this you can always scroll to the far right and read the last sentence. Now you should know what to do.
Rename the method in your repository to:
public interface UserRepo extends JpaRepository<User, Long> {
User findByName(String UserName);
}
You don't need to write the entity name in the method signature. After findBy the name of the field should follow, which is name (camelCase).

How to fix the Java exception "SQLSyntaxErrorException: Table 'x.y' doesn't exist"

I am build an online shopping application. The application was working fine until I added payment model, payment resource, payment service, payment repository. I tried dropping the entire database after creating the payment model but still it did not work. I don't know what seems to be a problem.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.2.RELEASE)
2019-11-28 08:48:46.797 INFO 6220 --- [ main] com.myshop.OnlineshoppingApplication : Starting OnlineshoppingApplication on BooTCamp1 with PID 6220 (C:\Users\Reverside\Documents\reverside\final\workproject\onlineshopping\target\classes started by Reverside in C:\Users\Reverside\Documents\reverside\final\workproject\onlineshopping)
2019-11-28 08:48:46.800 INFO 6220 --- [ main] com.myshop.OnlineshoppingApplication : No active profile set, falling back to default profiles: default
2019-11-28 08:48:48.099 INFO 6220 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3ee0fea4: startup date [Thu Nov 28 08:48:48 CAT 2019]; root of context hierarchy
2019-11-28 08:48:49.256 INFO 6220 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-11-28 08:48:49.387 INFO 6220 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-11-28 08:48:49.483 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.UserRepository.
2019-11-28 08:48:49.484 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.CartItemRepository.
2019-11-28 08:48:49.484 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.ProductToCartItemRepository.
2019-11-28 08:48:49.484 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.DeliveryAddressRepository.
2019-11-28 08:48:49.485 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.UserBillingRepository.
2019-11-28 08:48:49.485 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.UserPaymentRepository.
2019-11-28 08:48:49.485 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.OrderRepository.
2019-11-28 08:48:49.485 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.UserDeliveryRepository.
2019-11-28 08:48:49.486 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.RoleRepository.
2019-11-28 08:48:49.486 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.ProductRepository.
2019-11-28 08:48:49.486 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.ShoppingCartRepository.
2019-11-28 08:48:49.487 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.BillingAddressRepository.
2019-11-28 08:48:49.487 INFO 6220 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.myshop.repository.PaymentRepository.
2019-11-28 08:48:49.997 INFO 6220 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$7d6e0f9b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-28 08:48:50.587 INFO 6220 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-11-28 08:48:50.613 INFO 6220 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2019-11-28 08:48:50.615 INFO 6220 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.11
2019-11-28 08:48:50.998 INFO 6220 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-28 08:48:50.999 INFO 6220 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2912 ms
2019-11-28 08:48:51.151 INFO 6220 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-11-28 08:48:51.163 INFO 6220 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-11-28 08:48:51.163 INFO 6220 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-11-28 08:48:51.163 INFO 6220 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-11-28 08:48:51.164 INFO 6220 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2019-11-28 08:48:51.164 INFO 6220 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-11-28 08:48:52.006 INFO 6220 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-11-28 08:48:52.029 INFO 6220 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-11-28 08:48:52.251 INFO 6220 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2019-11-28 08:48:52.253 INFO 6220 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-11-28 08:48:52.265 INFO 6220 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2019-11-28 08:48:52.482 INFO 6220 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-11-28 08:48:52.784 INFO 6220 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-11-28 08:48:54.230 INFO 6220 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2019-11-28 08:48:54.383 INFO 6220 --- [ main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: payment
2019-11-28 08:48:54.556 WARN 6220 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2019-11-28 08:48:54.566 INFO 6220 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2019-11-28 08:48:54.581 WARN 6220 --- [ main] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)
2019-11-28 08:48:54.588 ERROR 6220 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at com.myshop.OnlineshoppingApplication.main(OnlineshoppingApplication.java:28) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 16 common frames omitted
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table payment add column id bigint not null]
at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:449) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.migrateTable(SchemaMigratorImpl.java:253) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:170) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
... 22 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: Table 'shopdb.payment' doesn't exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1355) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2128) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1264) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
... 32 common frames omitted
POM FILE
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myshop</groupId>
<artifactId>myshop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>onlineshopping</name>
<description>onlineshopping</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is this payment model I created
package com.myshop.domainModel;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import com.fasterxml.jackson.annotation.JsonIgnore;
#Entity
public class Payment implements Serializable{
private static final long serialVersionUID = 79151235145L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String type;
private String cardNumber;
private int expiryMonth;
private int expiryYear;
private int cvc;
private String holderName;
private boolean defaultPayment;
#OneToOne
#JsonIgnore
private Order order;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
public int getExpiryMonth() {
return expiryMonth;
}
public void setExpiryMonth(int expiryMonth) {
this.expiryMonth = expiryMonth;
}
public int getExpiryYear() {
return expiryYear;
}
public void setExpiryYear(int expiryYear) {
this.expiryYear = expiryYear;
}
public int getCvc() {
return cvc;
}
public void setCvc(int cvc) {
this.cvc = cvc;
}
public String getHolderName() {
return holderName;
}
public void setHolderName(String holderName) {
this.holderName = holderName;
}
public boolean isDefaultPayment() {
return defaultPayment;
}
public void setDefaultPayment(boolean defaultPayment) {
this.defaultPayment = defaultPayment;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}
Your error clearly pointed that you have not created database table : shopdb.payment.
And because of that your persistence flow getting break(Error : creating bean with entity manager relate with that).
If you don't want to put any configuration for auto generate table then create manually but if you do that dynamically then,
There is several reasons for database table not created at run time:
AutoConfiguration aren't work properly. Add annotation(Given Or other provided by spring),
#EnableAutoConfiguration
#PropertySource
#EntityScan
Database configuration and auto creation statement not properly placed in application.configuration / application.yml file.
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/shopdb
spring.datasource.username=database_username
spring.datasource.password=database_password
Here some case you need to create default schema of your database.
In some situation case sensitivity create ideal role when you do this kind of activity,
I highly recommended that define #Table, #Column annotation or Lombok kind of library(If supportable to your version).
Check your column name as per your requirement(Not related with error).
Also verify your mapping is exist, place and work properly with private context.
You will need to create the database manually
and check whether your application.properties file or YML file has the following configuration
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.username=username
spring.datasource.password=password
Below is a good tutorial to learn more about data persistence.
Accessing data with MySQL

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure AND BeanEntityManager error

Have had to cut the first error message quite abit since it contained to many characters, but the full thing can be found here: https://github.com/kableiv/FullSpringError
Bit of backstory:
Completing an assignment and need to create a small website where 2 predefined users can login, one with user privileges and one with admin, the privileges are buttons that redirect you to pages where you edit, delete and register new info. At first I did it without spring security and no database, using arraylists and files. When I logged in with the user it only had the user privileges like it was supposed to, however when I logged in with the admin and then went onto any of the other html pages like the one used to edit something and then clicked on the return button, the admin privileges were gone. Im assuming this was because i, in my method to login, sat its admin value to true(so the html page knew what to display and what not to) and then when that method was done and a new one was starting like the editing method the value was back to null.
Because of this I decided to try and switch to using a MySQL database with spring security.
My IDE of choice is intellij ultimate and I used MySQL Workbench to setup the database and added it into intellij using the database feature.
Now when trying to run the project i get the following error:
2018-05-04 16:59:10.780 INFO 8364 --- [ main] com.rfboernehave.demo.DemoApplication : Starting DemoApplication on DESKTOP-QB8IIQF with PID 8364 (C:\Users\nerdi\SpringbootWebAppMiniproject1\target\classes started by nerdi in C:\Users\nerdi\SpringbootWebAppMiniproject1)
2018-05-04 16:59:10.783 INFO 8364 --- [ main] com.rfboernehave.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-05-04 16:59:11.390 INFO 8364 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#516be40f: startup date [Fri May 04 16:59:11 CEST 2018]; root of context hierarchy
2018-05-04 16:59:14.723 INFO 8364 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 5000 (http)
2018-05-04 16:59:14.747 INFO 8364 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-05-04 16:59:14.747 INFO 8364 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2018-05-04 16:59:15.021 INFO 8364 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-05-04 16:59:15.021 INFO 8364 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3638 ms
2018-05-04 16:59:15.343 INFO 8364 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-04 16:59:15.343 INFO 8364 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-04 16:59:15.343 INFO 8364 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-04 16:59:15.343 INFO 8364 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-04 16:59:15.343 INFO 8364 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-05-04 16:59:15.347 INFO 8364 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-05-04 16:59:18.235 ERROR 8364 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2196) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2229) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) ~[mysql-connector-java-5.1.43.jar:5.1.43]
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735) [tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667) [tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482) [tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154) [tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) [tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) [tomcat-jdbc-8.5.16.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) [tomcat-jdbc-8.5.16.jar:na]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) [spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) [spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326) [spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366) [spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72) [spring-boot-autoconfigure-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139) [spring-boot-autoconfigure-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105) [spring-boot-autoconfigure-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$e4aac97b.CGLIB$jpaVendorAdapter$5(<generated>) [spring-boot-autoconfigure-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$e4aac97b$$FastClassBySpringCGLIB$$6844864e.invoke(<generated>) [spring-boot-autoconfigure-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at com.rfboernehave.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
NOW I have tried adding hibernating dependencies:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
Which gave me this other error instead:
:: Spring Boot :: (v1.5.6.RELEASE)
2018-05-04 16:36:20.358 INFO 19272 --- [ main] com.rfboernehave.demo.DemoApplication : Starting DemoApplication on DESKTOP-QB8IIQF with PID 19272 (C:\Users\nerdi\SpringbootWebAppMiniproject1\target\classes started by nerdi in C:\Users\nerdi\SpringbootWebAppMiniproject1)
2018-05-04 16:36:20.358 INFO 19272 --- [ main] com.rfboernehave.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-05-04 16:36:21.064 INFO 19272 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#77be656f: startup date [Fri May 04 16:36:21 CEST 2018]; root of context hierarchy
2018-05-04 16:36:23.488 INFO 19272 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 5000 (http)
2018-05-04 16:36:23.501 INFO 19272 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-05-04 16:36:23.501 INFO 19272 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2018-05-04 16:36:23.722 INFO 19272 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-05-04 16:36:23.722 INFO 19272 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2658 ms
2018-05-04 16:36:23.935 INFO 19272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-04 16:36:23.935 INFO 19272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-04 16:36:23.935 INFO 19272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-04 16:36:23.935 INFO 19272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-04 16:36:23.938 INFO 19272 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-05-04 16:36:23.939 INFO 19272 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-05-04 16:36:24.010 WARN 19272 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController' defined in file [C:\Users\nerdi\SpringbootWebAppMiniproject1\target\classes\com\rfboernehave\demo\controller\HomeController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'brugerServiceImpl' defined in file [C:\Users\nerdi\SpringbootWebAppMiniproject1\target\classes\com\rfboernehave\demo\services\BrugerServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brugerRepository': Cannot create inner bean '(inner bean)#703feacd' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#703feacd': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2018-05-04 16:36:24.012 INFO 19272 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-05-04 16:36:24.036 INFO 19272 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-05-04 16:36:24.114 ERROR 19272 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.rfboernehave.demo.services.BrugerServiceImpl required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
NOW I also got rid of this thing(not sure if did it correctly though) but it gave me a similair error but asking me to define a bean of type package. I decided to remove the dependencies and are therefore currently sitting with the first error of the post.
Below is my current pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rfboernhave</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<org.springframework.security.version>3.2.3.RELEASE</org.springframework.security.version>
<org.springframework.version>4.0.4.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>oss-parent</artifactId>
<version>27</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
My application.properties:
server.port=5000
spring.datasource.url=jdbc:mysql://localhost:5000/test_db
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
My Config.java class:
package com.rfboernehave.demo.Security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import javax.sql.DataSource;
#Configuration
#EnableWebSecurity
public class Config extends WebSecurityConfigurerAdapter {
#Autowired
DataSource dataSource;
#Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select username, password from user where username=?")
.authoritiesByUsernameQuery("select username, rolle from user where username=?");
}
#Override
protected void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.antMatchers("/login*").anonymous()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/home")
.and()
.logout().logoutSuccessUrl("/login");
}
}
My entity(MyUser) class : I apologize for the variables being in a foreign language quick translation:
MinBruger is (MyUser)
brugernavn is (username)
adgangskode is (password)
rolle is (role)
package com.rfboernehave.demo.domains;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class MinBruger {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private String brugernavn;
private String adgangskode;
private String rolle;
private int id;
public MinBruger() {
}
public MinBruger(int id, String brugernavn, String adgangskode, String rolle) {
this.id = id;
this.brugernavn = brugernavn;
this.adgangskode = adgangskode;
this.rolle = rolle;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBrugernavn() {
return brugernavn;
}
public void setBrugernavn(String brugernavn) {
this.brugernavn = brugernavn;
}
public String getAdgangskode() {
return adgangskode;
}
public void setAdgangskode(String adgangskode) {
this.adgangskode = adgangskode;
}
public String getRolle(){return rolle;}
public void setRolle(String rolle) {
this.rolle = rolle;
}
#Override
public String toString() {
return "MinBruger{" +
"id=" + id +
", brugernavn='" + brugernavn + '\'' +
", adgangskode='" + adgangskode + '\'' +
", rolle=" + rolle + '\'' +
'}';
}
Below is my UserRepository:
Translation:
BrugerRepository is (UserRepository)
package com.rfboernehave.demo.repositories;
import com.rfboernehave.demo.domains.MinBruger;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
#Repository
public interface BrugerRepository extends CrudRepository<MinBruger, String> {
}
How can I fix this?
Thx in Advance.
UPDATE: Ok so I sat the property:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Aside from that I also changed the following:
spring.datasource.url=jdbc:mysql://localhost:3306/
TO:
spring.datasource.url=jdbc:mysql://localhost:3306/test_db?useSSL=false
This seemed to do part of the trick, my project now runs, however a new problem arisen, when trying to login it fails and sets the url from: http://localhost:5000/login
TO: http://localhost:5000/login?error
Below is my HomeController.java:
package com.rfboernehave.demo.controller;
import com.rfboernehave.demo.domains.Barn;
import com.rfboernehave.demo.domains.MinBruger;
import com.rfboernehave.demo.services.BarnServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.io.FileNotFoundException;
import java.util.ArrayList;
#Controller
public class HomeController {
private final Logger log = LoggerFactory.getLogger(this.getClass());
#Autowired
private BarnServiceImpl barnService;
public HomeController() {
}
#RequestMapping(value = {"", "/", "index"}, method = RequestMethod.GET)
public String index() {
log.info("index method called...");
return "login";
}
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String login() {
log.info("login method called with: ");
if (SecurityContextHolder.getContext().getAuthentication().getAuthorities().contains(new SimpleGrantedAuthority("admin"))) {
return "redirect:/home";
}
return "login";
}
//
//
#RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Model model) {
log.info("home action called...");
model.addAttribute("boern", barnService.hentAlleBoern());
log.info("home action ended...");
return "home";
}
#GetMapping("/registrer")
public String registrer(Model model) {
log.info("registrer action called...");
model.addAttribute("barn", new Barn());
return "registrer";
}
#PostMapping("/registrer")
public String registrer(#ModelAttribute Barn barn, Model model) throws FileNotFoundException {
log.info("registrer post action called...");
String home = Integer.toString(barnService.hentAlleBoern().size());
barn.setId(Integer.parseInt(home));
barnService.hentAlleBoern().add(barn);
barnService.printToFile();
model.addAttribute("boern", barnService.hentAlleBoern());
return "/home";
}
#GetMapping("/detaljer/{id}")
public String detaljer(#PathVariable("id") int id, Model model) {
log.info("detaljer action called...");
Barn lille = null;
for (Barn barn : barnService.hentAlleBoern()) {
if (barn.getId() == id) {
lille = barn;
break;
}
}
model.addAttribute("barn", lille);
model.addAttribute("boern", barnService.hentAlleBoern());
return "detaljer";
}
#GetMapping("/afmeld/{id}")
public String afmeld(#PathVariable("id") int id, Model model) {
log.info("afmeld action called...");
model.addAttribute("barn",barnService.hentAlleBoern().get(id));
model.addAttribute("boern", barnService.hentAlleBoern());
return "afmeld";
}
#PostMapping("/afmeld")
public String afmeld(#ModelAttribute Barn barn, Model model) throws FileNotFoundException {
log.info("afmeld post action called...");
int id = barn.getId();
barnService.hentAlleBoern().remove(barn.getId());
leftShiftId(barnService.hentAlleBoern(), id);
barnService.printToFile();
model.addAttribute("boern", barnService.hentAlleBoern());
return "/home";
}
#GetMapping("/rediger/{id}")
public String rediger(#PathVariable("id") int id, Model model) {
log.info("rediger action called...");
model.addAttribute("barn", barnService.hentAlleBoern().get(id));
model.addAttribute("boern", barnService.hentAlleBoern());
return "rediger";
}
#PostMapping("/rediger")
public String rediger(#ModelAttribute Barn barn, Model model) throws FileNotFoundException {
log.info("rediger post action called...");
for (int i = 0; i < barnService.hentAlleBoern().size(); i++) {
if (barn.getId() == barnService.hentAlleBoern().get(i).getId()) {
barnService.hentAlleBoern().set(i, barn);
break;
}
}
barnService.printToFile();
model.addAttribute("boern", barnService.hentAlleBoern());
return "/home";
}
private void leftShiftId(ArrayList<Barn> list, int id) {
log.info("leftshift method called...");
for (int i = id; i < list.size(); i++) {
Barn barn = list.get(i);
barn.setId(barn.getId() - 1);
}
}
}
Below is the terminal output:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2018-05-08 13:18:32.979 INFO 1872 --- [ main] com.rfboernehave.demo.DemoApplication : Starting DemoApplication on DESKTOP-QB8IIQF with PID 1872 (C:\Users\nerdi\SpringbootWebAppMiniproject1\target\classes started by nerdi in C:\Users\nerdi\SpringbootWebAppMiniproject1)
2018-05-08 13:18:32.982 INFO 1872 --- [ main] com.rfboernehave.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-05-08 13:18:33.671 INFO 1872 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#516be40f: startup date [Tue May 08 13:18:33 CEST 2018]; root of context hierarchy
2018-05-08 13:18:36.652 INFO 1872 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 5000 (http)
2018-05-08 13:18:36.666 INFO 1872 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-05-08 13:18:36.667 INFO 1872 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2018-05-08 13:18:36.878 INFO 1872 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-05-08 13:18:36.878 INFO 1872 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3210 ms
2018-05-08 13:18:37.170 INFO 1872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-08 13:18:37.170 INFO 1872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-08 13:18:37.170 INFO 1872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-08 13:18:37.170 INFO 1872 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-05-08 13:18:37.172 INFO 1872 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-05-08 13:18:37.172 INFO 1872 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-05-08 13:18:37.907 INFO 1872 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-05-08 13:18:37.929 INFO 1872 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-05-08 13:18:38.204 INFO 1872 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2018-05-08 13:18:38.205 INFO 1872 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-05-08 13:18:38.207 INFO 1872 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2018-05-08 13:18:38.256 INFO 1872 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-05-08 13:18:38.425 INFO 1872 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-05-08 13:18:39.001 INFO 1872 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-05-08 13:18:39.571 INFO 1872 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#11b5f4e2, org.springframework.security.web.context.SecurityContextPersistenceFilter#33e0c716, org.springframework.security.web.header.HeaderWriterFilter#634ca3e7, org.springframework.security.web.csrf.CsrfFilter#6ee88e21, org.springframework.security.web.authentication.logout.LogoutFilter#d653e41, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#17222c11, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#6274f21c, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#12952aff, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#6bcae9, org.springframework.security.web.session.SessionManagementFilter#b14b60a, org.springframework.security.web.access.ExceptionTranslationFilter#50b734c4, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#67688110]
2018-05-08 13:18:40.196 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#516be40f: startup date [Tue May 08 13:18:33 CEST 2018]; root of context hierarchy
2018-05-08 13:18:40.337 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[ || / || /index],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.index()
2018-05-08 13:18:40.338 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/home],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.home(org.springframework.ui.Model)
2018-05-08 13:18:40.339 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/rediger],methods=[POST]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.rediger(com.rfboernehave.demo.domains.Barn,org.springframework.ui.Model) throws java.io.FileNotFoundException
2018-05-08 13:18:40.339 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/rediger/{id}],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.rediger(int,org.springframework.ui.Model)
2018-05-08 13:18:40.340 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/detaljer/{id}],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.detaljer(int,org.springframework.ui.Model)
2018-05-08 13:18:40.341 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/login],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.login()
2018-05-08 13:18:40.342 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/registrer],methods=[POST]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.registrer(com.rfboernehave.demo.domains.Barn,org.springframework.ui.Model) throws java.io.FileNotFoundException
2018-05-08 13:18:40.342 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/registrer],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.registrer(org.springframework.ui.Model)
2018-05-08 13:18:40.343 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/afmeld],methods=[POST]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.afmeld(com.rfboernehave.demo.domains.Barn,org.springframework.ui.Model) throws java.io.FileNotFoundException
2018-05-08 13:18:40.344 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/afmeld/{id}],methods=[GET]}" onto public java.lang.String com.rfboernehave.demo.controller.HomeController.afmeld(int,org.springframework.ui.Model)
2018-05-08 13:18:40.347 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-05-08 13:18:40.348 INFO 1872 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-05-08 13:18:40.398 INFO 1872 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-08 13:18:40.400 INFO 1872 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-08 13:18:40.477 INFO 1872 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-08 13:18:41.111 INFO 1872 --- [ main] b.a.s.AuthenticationManagerConfiguration :
Using default security password: 4f2b3afb-8328-4fa1-a16c-e16003f15618
2018-05-08 13:18:41.294 INFO 1872 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-05-08 13:18:41.396 INFO 1872 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 5000 (http)
2018-05-08 13:18:41.403 INFO 1872 --- [ main] com.rfboernehave.demo.DemoApplication : Started DemoApplication in 8.91 seconds (JVM running for 9.612)

Unable to build Hibernate SessionFactory using spring boot jpa

At first I have a model named person. It worked well and create a table in my database. After I add a new model that have a foreign key to it, I have this problem. I don't have a dbconfig.java. I just have a application.properties. like this.
spring.thymeleaf.mode=LEGACYHTML5
# Database
spring.datasource.url=jdbc:mysql://localhost:3306/db_example?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# Hibernate
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jackson.serialization.indent-output=true
And here are the models
person.java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
#Entity
#NoArgsConstructor
#AllArgsConstructor
#Data
#NamedQuery(name="Person.withNameAndcollegeNamedQuery", query = "select p from Person p where p.name=?1 and p.college=?2")
public class Person {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
private Integer age;
private String college;
private String title;
}
project,java
package com.example.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
#Entity
#NoArgsConstructor
#AllArgsConstructor
#Data
#NamedQuery(name="Record.withNmaeAndAddressNamedQuery", query = "select p from Record p where p.name=?1 and address=?2")
public class Project {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String projectName;
#OneToOne
private Person person;
private String description;
private Subject subject;
private String date;
}
And this is the console log:
13:30:30.244 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
13:30:30.247 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
13:30:30.248 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/E:/workspace-sts-3.8.4.RELEASE/demo/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2017-08-11 13:30:30.474 INFO 12108 --- [ restartedMain] com.example.DemoApplication : Starting DemoApplication on MoriatyC with PID 12108 (E:\workspace-sts-3.8.4.RELEASE\demo\target\classes started by cmh in E:\workspace-sts-3.8.4.RELEASE\demo)
2017-08-11 13:30:30.475 INFO 12108 --- [ restartedMain] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2017-08-11 13:30:30.652 INFO 12108 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2350e3c9: startup date [Fri Aug 11 13:30:30 CST 2017]; root of context hierarchy
2017-08-11 13:30:32.149 INFO 12108 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-08-11 13:30:32.157 INFO 12108 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-08-11 13:30:32.158 INFO 12108 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-08-11 13:30:32.230 INFO 12108 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-08-11 13:30:32.230 INFO 12108 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1580 ms
2017-08-11 13:30:32.350 INFO 12108 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-11 13:30:32.353 INFO 12108 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-08-11 13:30:32.353 INFO 12108 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-08-11 13:30:32.353 INFO 12108 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-08-11 13:30:32.354 INFO 12108 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-08-11 13:30:32.806 INFO 12108 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-08-11 13:30:32.820 INFO 12108 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-08-11 13:30:32.954 INFO 12108 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-08-11 13:30:32.955 INFO 12108 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-08-11 13:30:32.956 INFO 12108 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-08-11 13:30:32.988 INFO 12108 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-08-11 13:30:33.074 INFO 12108 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-08-11 13:30:33.232 WARN 12108 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2017-08-11 13:30:33.237 INFO 12108 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-08-11 13:30:33.249 INFO 12108 --- [ restartedMain] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-08-11 13:30:33.257 ERROR 12108 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at com.example.DemoApplication.main(DemoApplication.java:13) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.6.RELEASE.jar:1.5.6.RELEASE]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 21 common frames omitted
Caused by: org.hibernate.MappingException: Could not determine type for: com.example.model.Subject, at table: project, for columns: [org.hibernate.mapping.Column(subject)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:431) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:398) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.mapping.Property.isValid(Property.java:225) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:595) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:265) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
... 27 common frames omitted
Where is the problem?
First of all you have to create a Subject entity and map it to your Projects entity with #OneToOne
Add
#OneToOne
private Subject subject;
in your Project.java file.
Subject.java
package com.example.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class Subject {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
//Other fields according to your need and setter/getter
}
After creating the Subject entity you get an error in your Project entity at #NamedQuery line so you have to change your named query like below (you can change fields according to your need)
#NamedQuery(name="Project.withProjectNameAndDescriptionQuery", query = "select p from Project p where p.projectName=?1 and p.description=?2")
then problem is Caused by: org.hibernate.MappingException: Could not determine type for: com.example.model.Subject, at table: project, for columns: [org.hibernate.mapping.Column(subject)]. you are using private Subject subject; into Project entity, and the column name Subject is not determining. so if Subject entity is present into your entity package the you need to #JoinColumn(name = "SUBJECT_ID") or you can also use another column for mapping.
#ManyToOne
#JoinColumn(name = "CITY_ID")
private Subject subject;
You have a mapping exception. You are using a field subject in your Person Entity which is of Subject class.
Hibernate cannot map a field with a complex type to a simple column. It has to be an entity defined and mapped.
So, to solve your problem, define the class Subject as an entity, map it to your probably already existing Subject table in DB, and then specify the relationship between Person and Subject by annotating the field subject with the appropriate annotation (#ManyToOne or #OneToOne) and any #JoinColumn necessary.
By the way I would recommend to define your mapping columns explicitly (annotation #Column if Hibernate doesn't generate the schema. That will allow you to change your variable names without need to change database column names

Spring Boot: Repository and Entity beans not recognized error

My code doesn't seem to recognize some of my repositories and entity classes. I have two databases, LoadMethod and MTS, that I am dealing with. I have had this error for about two days and everything I've found online has mentioned bad package names or missing annotations, but I seem to have all of that to my knowledge.
This is my project package structure:
This is my console output:
2016-08-16 09:03:13.310 INFO 4724 --- [ main] database.Application : Starting Application on LR90KLWJY with PID 4724 (C:\Users\vincni\git\consumer_load_method\bin started by vincni in C:\Users\vincni\git\consumer_load_method)
2016-08-16 09:03:13.313 INFO 4724 --- [ main] database.Application : No active profile set, falling back to default profiles: default
2016-08-16 09:03:13.357 INFO 4724 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#15bfd87: startup date [Tue Aug 16 09:03:13 PDT 2016]; root of context hierarchy
2016-08-16 09:03:14.080 INFO 4724 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'TBL_GroupRepository' with a different definition: replacing [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2016-08-16 09:03:14.652 INFO 4724 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'lmPersistenceUnit'
2016-08-16 09:03:14.679 INFO 4724 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: lmPersistenceUnit
...]
2016-08-16 09:03:14.757 INFO 4724 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
2016-08-16 09:03:14.758 INFO 4724 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-08-16 09:03:14.760 INFO 4724 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-08-16 09:03:14.960 INFO 4724 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-08-16 09:03:15.715 WARN 4724 --- [ main] o.h.e.j.d.i.StandardDialectResolver : HHH000385: Unknown Microsoft SQL Server major version [12] using SQL Server 2000 dialect
2016-08-16 09:03:15.720 INFO 4724 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
2016-08-16 09:03:15.851 INFO 4724 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-08-16 09:03:16.062 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2016-08-16 09:03:16.062 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000102: Fetching database metadata
2016-08-16 09:03:16.063 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000396: Updating schema
2016-08-16 09:03:16.090 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: dbMOBClientTemp.dbo.Client
2016-08-16 09:03:16.090 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [expndedidind, isd_lupd_ts, client_id, isd_lupd_id]
2016-08-16 09:03:16.090 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: []
2016-08-16 09:03:16.090 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [pxclient]
2016-08-16 09:03:16.101 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: dbMOBClientTemp.dbo.LoadMethod
2016-08-16 09:03:16.101 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [actind, loadmthdcd, dtltransrcdind, media_id, acctmngdind, formatmapcd, isd_lupd_ts, isd_lupd_id]
2016-08-16 09:03:16.101 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: []
2016-08-16 09:03:16.101 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [pxldmthd]
2016-08-16 09:03:16.110 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: dbMOBClientTemp.dbo.LoadMethodClient
2016-08-16 09:03:16.110 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [media_id, isd_lupd_ts, client_id, isd_lupd_id]
2016-08-16 09:03:16.110 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: [rcmedialm, rcclientlm]
2016-08-16 09:03:16.110 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [pxlmc]
2016-08-16 09:03:16.117 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: dbMOBClientTemp.dbo.LoadMethodComments
2016-08-16 09:03:16.117 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [ec_sk, media_id, cmt, isd_lupd_ts, isd_lupd_id]
2016-08-16 09:03:16.118 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: [rcmediaid]
2016-08-16 09:03:16.118 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [pxlmcmt]
2016-08-16 09:03:16.118 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000232: Schema update complete
2016-08-16 09:03:16.163 INFO 4724 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'mtsPersistentUnit'
2016-08-16 09:03:16.163 INFO 4724 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: mtsPersistentUnit
...]
2016-08-16 09:03:16.382 INFO 4724 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
2016-08-16 09:03:16.386 INFO 4724 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-08-16 09:03:16.392 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2016-08-16 09:03:16.392 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000102: Fetching database metadata
2016-08-16 09:03:16.392 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000396: Updating schema
2016-08-16 09:03:16.418 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: dbMTS.dbo.tblGROUP
2016-08-16 09:03:16.418 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [date_updated, penalty_ind, media_count, y2k_advised, download_full, label_spec, who_entered, group_inactive, report_preference, edi_type, prod_test_ind, late_status, frequency, g_tech_num, media_type, control_number, hot_loadt, media_id, date_entered, id, mit_id, emc_synch_flag, who_updated, block_size, strategic_group, report_processor, format_program, gmisc_flag_2, gmisc_flag_1, gmisc_flag_3, record_size, four_digit_year, respon_anal, time_updated, open_enroll_mnth, use_tpa_contact, ol_id, fk_tpa_id, zeke_event, name, time_entered, package_name, group_maint_ind, elig_password, edt_advised, need_labels, spanned_zipfile]
2016-08-16 09:03:16.418 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000108: Foreign keys: [rcgrpadmin]
2016-08-16 09:03:16.418 INFO 4724 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000126: Indexes: [pxgroup]
2016-08-16 09:03:16.419 INFO 4724 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000232: Schema update complete
2016-08-16 09:03:16.628 WARN 4724 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TBL_GroupRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class database.mts.dataobjects.TBL_GroupDO
2016-08-16 09:03:16.630 INFO 4724 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'mtsPersistentUnit'
2016-08-16 09:03:16.630 INFO 4724 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'lmPersistenceUnit'
2016-08-16 09:03:16.636 ERROR 4724 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TBL_GroupRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class database.mts.dataobjects.TBL_GroupDO
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.3.6.RELEASE.jar:1.3.6.RELEASE]
at database.Application.main(Application.java:30) [bin/:na]
Caused by: java.lang.IllegalArgumentException: Not an managed type: class database.mts.dataobjects.TBL_GroupDO
at org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:219) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:68) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:67) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:152) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:99) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:81) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
... 15 common frames omitted
2016-08-16 09:03:16.639 INFO 4724 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Users/vincni/git/consumer_load_method/bin/, file:/C:/apps/Ivy/cache/org.apache.camel/camel-ftp/jars/camel-ftp-2.16.1.jar, file:/C:/apps/Ivy/cache/org.apache.camel/camel-core/bundles/camel-core-2.16.1.jar, file:/C:/apps/Ivy/cache/com.sun.xml.bind/jaxb-core/jars/jaxb-core-2.2.11.jar, file:/C:/apps/Ivy/cache/com.sun.xml.bind/jaxb-impl/jars/jaxb-impl-2.2.11.jar, file:/C:/apps/Ivy/cache/com.jcraft/jsch/jars/jsch-0.1.53.jar, file:/C:/apps/Ivy/cache/commons-net/commons-net/jars/commons-net-3.3.jar, file:/C:/apps/Ivy/cache/com.zaxxer/HikariCP/jars/HikariCP-2.4.7.jar, file:/C:/apps/Ivy/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.21.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot-starter-data-jpa/jars/spring-boot-starter-data-jpa-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot-starter/jars/spring-boot-starter-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot/jars/spring-boot-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-core/jars/spring-core-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-context/jars/spring-context-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-aop/jars/spring-aop-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/aopalliance/aopalliance/jars/aopalliance-1.0.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-beans/jars/spring-beans-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-expression/jars/spring-expression-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot-autoconfigure/jars/spring-boot-autoconfigure-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot-starter-logging/jars/spring-boot-starter-logging-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.7.jar, file:/C:/apps/Ivy/cache/ch.qos.logback/logback-core/jars/logback-core-1.1.7.jar, file:/C:/apps/Ivy/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.7.21.jar, file:/C:/apps/Ivy/cache/org.slf4j/jul-to-slf4j/jars/jul-to-slf4j-1.7.21.jar, file:/C:/apps/Ivy/cache/org.slf4j/log4j-over-slf4j/jars/log4j-over-slf4j-1.7.21.jar, file:/C:/apps/Ivy/cache/org.yaml/snakeyaml/bundles/snakeyaml-1.16.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot-starter-aop/jars/spring-boot-starter-aop-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.9.jar, file:/C:/apps/Ivy/cache/org.springframework.boot/spring-boot-starter-jdbc/jars/spring-boot-starter-jdbc-1.3.6.RELEASE.jar, file:/C:/apps/Ivy/cache/org.apache.tomcat/tomcat-jdbc/jars/tomcat-jdbc-8.0.36.jar, file:/C:/apps/Ivy/cache/org.apache.tomcat/tomcat-juli/jars/tomcat-juli-8.0.36.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-jdbc/jars/spring-jdbc-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-tx/jars/spring-tx-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.hibernate/hibernate-entitymanager/jars/hibernate-entitymanager-4.3.11.Final.jar, file:/C:/apps/Ivy/cache/org.jboss.logging/jboss-logging/jars/jboss-logging-3.3.0.Final.jar, file:/C:/apps/Ivy/cache/org.jboss.logging/jboss-logging-annotations/jars/jboss-logging-annotations-1.2.0.Beta1.jar, file:/C:/apps/Ivy/cache/org.hibernate/hibernate-core/jars/hibernate-core-4.3.11.Final.jar, file:/C:/apps/Ivy/cache/dom4j/dom4j/jars/dom4j-1.6.1.jar, file:/C:/apps/Ivy/cache/xml-apis/xml-apis/jars/xml-apis-1.0.b2.jar, file:/C:/apps/Ivy/cache/org.hibernate.common/hibernate-commons-annotations/jars/hibernate-commons-annotations-4.0.5.Final.jar, file:/C:/apps/Ivy/cache/org.hibernate.javax.persistence/hibernate-jpa-2.1-api/jars/hibernate-jpa-2.1-api-1.0.0.Final.jar, file:/C:/apps/Ivy/cache/org.javassist/javassist/bundles/javassist-3.18.1-GA.jar, file:/C:/apps/Ivy/cache/antlr/antlr/jars/antlr-2.7.7.jar, file:/C:/apps/Ivy/cache/org.jboss/jandex/jars/jandex-1.1.0.Final.jar, file:/C:/apps/Ivy/cache/javax.transaction/javax.transaction-api/jars/javax.transaction-api-1.2.jar, file:/C:/apps/Ivy/cache/org.springframework.data/spring-data-jpa/jars/spring-data-jpa-1.9.4.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework.data/spring-data-commons/jars/spring-data-commons-1.11.4.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-orm/jars/spring-orm-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.springframework/spring-aspects/jars/spring-aspects-4.2.7.RELEASE.jar, file:/C:/apps/Ivy/cache/org.apache.camel/camel-jpa/jars/camel-jpa-2.10.0.jar, file:/C:/apps/Ivy/cache/org.apache.camel/camel-spring/bundles/camel-spring-2.10.0.jar, file:/C:/apps/Ivy/cache/org.apache.poi/poi/jars/poi-3.10.1.jar, file:/C:/apps/Ivy/cache/commons-codec/commons-codec/jars/commons-codec-1.5.jar, file:/C:/apps/Ivy/cache/org.apache.poi/poi-ooxml/jars/poi-ooxml-3.10.1.jar, file:/C:/apps/Ivy/cache/org.apache.poi/poi-ooxml-schemas/jars/poi-ooxml-schemas-3.10.1.jar, file:/C:/apps/Ivy/cache/org.apache.xmlbeans/xmlbeans/jars/xmlbeans-2.6.0.jar, file:/C:/apps/Ivy/cache/stax/stax-api/jars/stax-api-1.0.1.jar, file:/C:/apps/Ivy/cache/com.microsoft.sqlserver/sqljdbc4/jars/sqljdbc4-4.0.jar, file:/C:/ExternalJARS/ojdbc7.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/eclipselink.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/jpa/javax.persistence_2.1.0.v201304241213.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/jpa/org.eclipse.persistence.jpa.modelgen_2.5.2.v20140319-9ad6abd.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/jpa/org.eclipse.persistence.jpars_2.5.2.v20140319-9ad6abd.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/moxy/com.sun.tools.xjc_2.2.0.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/moxy/com.sun.xml.bind_2.2.0.v201004141950.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/moxy/javax.activation_1.1.0.v201108011116.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/moxy/javax.mail_1.4.0.v201005080615.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/moxy/javax.xml.bind_2.2.0.v201105210648.jar, file:/C:/Users/vincni/workspace/workspace_lmt/libraries/EclipseLink%202.5.2/eclipselink/jlib/moxy/javax.xml.stream_1.0.1.v201004272200.jar]
This is my config file:
package database.mts;
//all my imports//
#Configuration
#EnableJpaRepositories(entityManagerFactoryRef = "mtsEntityManagerFactory",
transactionManagerRef = "mtsTransactionManager")
public class MTS_Config {
#Bean
#Primary
#ConfigurationProperties(prefix="spring.mtsDatasource")
public DataSource mtsDataSource() {
return DataSourceBuilder.create().build();
}
#Bean
#Primary
LocalContainerEntityManagerFactoryBean mtsEntityManagerFactory(final EntityManagerFactoryBuilder builder) {
return builder.dataSource(mtsDataSource())
.packages("database.mts.dataobjects")
.persistenceUnit("mtsPersistentUnit")
.build();
}
#Bean
#Primary
PlatformTransactionManager mtsTransactionManager( #Qualifier("mtsEntityManagerFactory") final EntityManagerFactory factory ) {
return new JpaTransactionManager(factory);
}
}
This is my other config file:
package database.loadmethod;
#Configuration
#EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory",
transactionManagerRef = "transactionManager")
public class LM_Config {
#Bean
#ConfigurationProperties(prefix="spring.datasource")
public DataSource lmDataSource() {
return DataSourceBuilder.create().build();
}
#Bean(name = "entityManagerFactory")
LocalContainerEntityManagerFactoryBean lmEntityManagerFactory(final EntityManagerFactoryBuilder builder) {
return builder.dataSource(lmDataSource())
.packages("database.loadmethod.dataobjects")
.persistenceUnit("lmPersistenceUnit")
.build();
}
#Bean(name = "transactionManager")
PlatformTransactionManager lmTransactionManager( #Qualifier("entityManagerFactory") final EntityManagerFactory factory ) {
return new JpaTransactionManager(factory);
}
}
This is my entity object of interest (the one that doesnt seem to be recognized):
package database.mts.dataobjects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="tblGROUP")
public class TBL_GroupDO {
#Id
#Column(name="ID")
private String id;
#Column(name="MEDIA_ID")
private String mediaId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMediaId() {
return mediaId;
}
public void setMediaId(String mediaId) {
this.mediaId = mediaId;
}
}
This is the repository of interest:
package database.mts.repositories;
import org.springframework.data.repository.CrudRepository;
import database.mts.dataobjects.TBL_GroupDO;
public interface TBL_GroupRepository extends CrudRepository<TBL_GroupDO, String>{
}
This is my application file:
package database;
//imports//
#SpringBootApplication//(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class})
#EnableJpaRepositories //(basePackages = {"database.loadmethod.repositories", "database.mts.repositories"})
//#EntityScan(basePackages = {"database.loadmethod.dataobjects", "database.mts.dataobjects"})
//#EntityScan
//#EnableTransactionManagement
public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Bean
public CommandLineRunner demo(LoadMethodRepository lm_repo, TBL_GroupRepository tblg_repo /*, LMClientRepository lmc_repo */) {
return (args) -> {
System.out.println("*********Media ID**************");
System.out.println(lm_repo.findOne("4948460").getMediaId());
System.out.println("*********Media ID**************");
System.out.println(tblg_repo.findOne("8").getMediaId());
System.out.println("*********Media ID**************");
};
}
}
This is my properties file:
spring.jpa.generate-ddl=true
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.DefaultNamingStrategy
spring.datasource.username=xxxx
spring.datasource.password=xxx
spring.datasource.url=jdbc:sqlserver://xxx:1433;database=xxx;integratedSecurity=false;
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.jpa.database=xxx
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.mtsDatasource.username=xxx
spring.mtsDatasource.password=xxxxx
spring.mtsDatasource.url=jdbc:sqlserver://VSQLCON2:1433;database=dbMTS;integratedSecurity=false;
spring.mtsDatasource.testOnBorrow=true
spring.mtsDatasource.validationQuery=SELECT 1
spring.mtsDatasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.default_schema=dbo
hibernate.packagesToScan=src.repositories.LMClientRepository.java

Categories