0

I have a Java project in eclipse where i have used mysql earlier i implemented spring and i am now about to switch database to postgresql and i also want to implement springboot with gradle and switch my xml based config to java based config. in xml i have the following dataconfig.xml and when i swapped the earlier jdbc for mysql to jdbc for postgresql i got the app running on server.

<!-- Simple implementation of the standard JDBC DataSource interface, configuring 
        the plain old JDBC DriverManager via bean properties -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url"
            value="jdbc:postgresql://localhost:5432/up2u_user" />
        <property name="username" value="up2u_user2" />
        <property name="password" value="e2f2c2ac87" />
    </bean>

    <!-- This produces a container-managed EntityManagerFactory; rather than 
        application-managed EntityManagerFactory as in case of LocalEntityManagerFactoryBean -->
    <bean id="entityManagerFactoryBean"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />

        <!-- This makes /META-INF/persistence.xml is no longer necessary -->
        <property name="packagesToScan" value="se.up2u.flowkeeper.*" />

        <!-- JpaVendorAdapter implementation for Hibernate EntityManager. Exposes 
            Hibernate's persistence provider and EntityManager extension interface -->
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.connection.pool_size">0</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.event.merge.entity_copy_observer">allow</prop>
                <prop key="hibernate.temp.use_jdbc_metadata_defaults">true</prop>
            </props>
        </property>
    </bean>
</beans>

now to my problem i have the following files in my new springboot gradle project...

This is my application.properties file.

# General JPA properties
spring.jpa.database=POSTGRESQL
spring.jpa.database-platform=postgres
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

# DataSource configuration
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/up2u_user
spring.datasource.username=up2u_user2
spring.datasource.password=password

# Hibernate Specific properties
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.hibernate.ddl-auto=create-drop

This is my dependencies.

dependencies {
    compile 'com.graphql-java:graphql-java:2.0.0'
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.security.oauth:spring-security-oauth2')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-jersey')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile group: 'postgresql', name: 'postgresql', version: '9.1-901-1.jdbc4'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

This is my application file.

@SpringBootApplication
@EnableAutoConfiguration
@EnableWebMvc
@EntityScan("se.up2u.flowkeeper.model.entity")
public class FlowKeeperCoreApplication {

    public static void main(String[] args) {
        SpringApplication.run(FlowKeeperCoreApplication.class, args);
    }
}

This is my configuration file that's quite empty atm...

@Configuration
@EnableWebSecurity
public class FlowKeeperConfig {
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
}

and when i try to run "gradle bootRun" i get the following stack-trace.

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.MappingException: class demo.fabric.Employee not found while looking for property: id
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.2.RELEASE.jar:4.3.2                                                        .RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
    at se.up2u.flowkeeper.FlowKeeperCoreApplication.main(FlowKeeperCoreApplication.java:16) [main/:na]
Caused by: org.hibernate.MappingException: class demo.fabric.Employee not found while looking for property: id
    at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:212) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:422) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindSimpleEntityIdentifier(ModelBinder.java:712) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindEntityIdentifier(ModelBinder.java:342) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindRootEntity(ModelBinder.java:237) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.boot.model.source.internal.hbm.ModelBinder.bindEntityHierarchy(ModelBinder.java:184) ~[hibernate-core-5.0.9.Final.ja                  r:5.0.9.Final]
    at org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl.processEntityHierarchies(HbmMetadataSourceProcessorImpl.java:144) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:218) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    ... 16 common fmittedo
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [demo.fabric.Employee]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:229) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:208) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    ... 32 common frames omitted
Caused by: java.lang.ClassNotFoundException: Could not load requested class : demo.fabric.Employee
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:217) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_92]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_92]
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_92]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_92]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:226) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
    ... 33 common frames omitted

I have understood that much that i should define beans to replace the default once but i don't really know how to do it? i have searched but haven't really understod what beans to create, what properties to change or what dependencies that is missing or unnecessary.

UPPDATE: The class and package that is mentioned in the stack trace is not in my project. i use package structure se.up2u.flowkeeper I just realised that the jdbc i use is what postgresql is referingto as jdbc41 that is intended for java 1.7 there is no jdbc42 that is for 1.8. also i get another error about unsatisfied dependency if i remove the postgresql dependency.

10
  • Error says your Entity class demo.fabric.Employee doesn't have a field that has been annotated as @Id. Caused by: org.hibernate.MappingException: class demo.fabric.Employee not found while looking for property: id Commented Aug 3, 2016 at 16:47
  • Yes but that is no class that i have in my project. i use packages named se.up2u.flowkeeper. and so on. when i add @Bean with entetymanagerFactory i get another error about TransactionManager but i cent get it all figured out it feels like i have missed something obvious. Commented Aug 3, 2016 at 17:44
  • Are running gradle from Eclipse? Check your classpath, it looks like you added another project as a dependency. BTW: github.com/asanciangco/CS143/blob/master/HW3/…, docs.oracle.com/cd/E17952_01/mysql-utilities-1.4-en/…. Commented Aug 3, 2016 at 18:05
  • no i'm running it from terminal on my macbook air. hmm intresting it's all my dependency's you can see up here. that was an intressting link but that's a mysql project. i'll try add that class and package and see what happens. Commented Aug 3, 2016 at 18:07
  • Have you tried to see your dependencies: gradle app:dependencies Commented Aug 3, 2016 at 18:09

1 Answer 1

1

For me the problem has been resolved by removing redundant mysql-connector-java.jar from java classpath (/lib/ext for me).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.