6

i have an spring boot Project A that depend to project B. project B have some .hbm.xml resources. in the project A for change hibernate configuration i add DatabaseConfiguration @Configuration for change sessionFactory

@Bean public LocalSessionFactoryBean sessionFactory() { LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean(); sessionFactoryBean.setDataSource(dataSource); sessionFactoryBean.setMappingLocations("classpath*:hibernate/**/*.hbm.xml"); Properties hibernateProperties = new Properties(); hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT); hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL); sessionFactoryBean.setHibernateProperties(hibernateProperties); return sessionFactoryBean; } 

build.gradle have this dependency HibernateJpaAutoConfiguration run

compile 'org.springframework.boot:spring-boot-starter-data-jpa' 

when i run application in gradle bootRun or maven spring-boot:run application start and ok but when i run in java -jar i get exception

 caused by: 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: An association from the table core_organization_Structure refers to an unmapped class: org.roshan.framework.domain.security.User 

i dont know why HibernateJpaAutoConfiguration start ??? after that i change Application.java to like this for exclude that but again not work .when i copy hbm to projectA .project A run and ok (with java -jar)

@SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class }) 

update

after search and test ,i found problem and solve that .cause of problem was using hibernate-entitymanager dependency in project.spring boot actuator detect this and auto config entity manager .after remove this dependency disable HibernateJpaAutoConfiguration work correct :D

6
  • What makes you think you need a plain SessionFactory to be able to use hbm.xml files? Those work perfectly fine with an entity manager (and generally are picked up as well). So instead of complicating things just use JPA. I find it strange that you don't get an error with bootRun (although I think I know why, as that properly configures a JPA entity manager and your packaged jar fails due to not being able to read your hbm files). Commented May 29, 2016 at 18:18
  • i have many hbm that can not migrate to jpa.why HibernateJpaAutoConfiguration exclude not work ? Commented May 29, 2016 at 18:24
  • Please read. The fact that you have a HBM file doesn't mean you cannot use JPA. Either annotations or xml there has to be a mapping for your entity, for a Hibernate based JPA provider it can use both. So just use JPA so just use the entity manager and it will work with a HBM file. Commented May 30, 2016 at 5:41
  • yes i think know what you say .i want to use SessionFactory and ignore HibernateJpaAutoConfiguration? how can i do it? . and dont know why in " "java - jar " application dont sens hbm in jar dependency ?? but when copy hbm in project a application start ok ???? Commented May 31, 2016 at 19:17
  • Then exclude the auto config. But why do you want to use a session factory? What does it give you over an EntityManager? Commented Jun 1, 2016 at 5:31

2 Answers 2

3

Try this to disable data source auto configuration:

import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.jdbc.*; import org.springframework.context.annotation.*; @Configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class MyConfiguration { } 
Sign up to request clarification or add additional context in comments.

Comments

2

after search and test ,i found problem ,cause of problem was using hibernate-entitymanager dependency in project.spring boot actuator detect this and auto config entity manager .after remove this dependency disable HibernateJpaAutoConfiguration work correct :D

1 Comment

what dependency was removed ? :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.