hibernate.properties找不到配置?

时间:2014-12-06 19:23:03

标签: java spring hibernate jpa

这是我的3个班级:

@Configuration //Marks this class as configuration
//Specifies which package to scan
@ComponentScan({"pl.jpet"})//,"pl.dup"})
//Enables Spring's annotations
@EnableWebMvc
//@EnableTransactionManagement
@PropertySource("classpath:application.properties")
public class Config {

    @Resource
    private Environment env;

    @Bean(name = "dataSource")
    public BasicDataSource dataSource() {

        BasicDataSource ds = new BasicDataSource();

        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/wikidb");
        ds.setUsername("root");
        ds.setPassword("root");

        return ds;
    }

    @Bean
    public HibernateExceptionTranslator hibernateExceptionTranslator() {
        return new HibernateExceptionTranslator();
    }

    @Bean
    @Autowired
    public EntityManagerFactory entityManagerFactory(BasicDataSource dataSource) {


        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");
        vendorAdapter.setDatabase(Database.MYSQL);

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setDataSource(dataSource);

        factory.setPersistenceUnitName("wikidb");
        factory.setPackagesToScan("pl.jpet");
        factory.afterPropertiesSet();

        return factory.getObject();
    }

    @Bean
    @Autowired
    public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {

        JpaTransactionManager txManager = new JpaTransactionManager();
        JpaDialect jpaDialect = new HibernateJpaDialect();
        txManager.setEntityManagerFactory(entityManagerFactory);
        txManager.setJpaDialect(jpaDialect);
        return txManager;
    }

----------------------------------------------------------------------

package pl.jpet.model;

import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Data
@Table(name="zrobmitabele") 
public class TestModel {

    @Id
    @Column(name = "name", nullable = false)
    private String name;

}


-----------------------------------------------------------------------------


@Transactional
@RestController
@RequestMapping("/una")
public class UnauthenticatedController {    
    @PersistenceContext
    private EntityManager em;

    @Transactional
    @RequestMapping(method = RequestMethod.GET,value="/checkLogin")
    public ResponseEntity<String> checkLogin() throws IOException {


            TestModel test = new TestModel();
            test.setName("KUBA");
            em.persist(test);

            return new ResponseEntity<String>(HttpStatus.OK);


    }




}

我在启动时收到此信息“INFO [org.hibernate.cfg.Environment](MSC服务线程1-1)HHH000206:找不到hibernate.properties”但是即使在我制作之后它仍然没有破碎打电话给“/ una”服务它没有扔任何东西 - 猜猜我的Config课有什么问题,但我不知道什么,有人吗?

1 个答案:

答案 0 :(得分:0)

我在配置类上错过了@EnableTransactionManagement @ _ @