相关疑难解决方法(0)

如何使用现代Spring Boot + Data JPA和Hibernate设置生成ddl创建脚本?

目前,我正在使用@SpringBootApplication具有以下属性的默认注释application.properties:

spring.datasource.url=jdbc:mysql://localhost/dbname
spring.datasource.username=X
spring.datasource.password=X
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.naming_strategy=my.package.CustomNamingStrategy
Run Code Online (Sandbox Code Playgroud)

从JPA 2.1开始,我应该可以使用这些javax.persistence.schema-generation.*属性,但是在我的application.properties中设置它们似乎没有任何效果.

我见过的例子是这样那丝了一大堆额外的豆子,但他们没有使用MySQL.无论如何,这样做需要我配置春天为我提供的许多选项.

我的目标是:

  • 在MYSQL方言中生成模式创建sql脚本
  • 没有数据库连接是必需的
  • 输出构建目录中的脚本
  • 同时生成hibernate envers表也是一个巨大的优势.

我不想:

  • 在实时数据库上创建/删除模式

Lib版本:

   hibernate          : 4.3.11.FINAL
   spring framework   : 4.2.5.RELEASE
   spring-boot        : 1.3.3.RELEASE
   spring-data-jpa    : 1.10.1.RELEASE   // for  querydsl 4 support
   spring-data-commons: 1.12.1.RELEASE   // for  querydsl 4 support
Run Code Online (Sandbox Code Playgroud)

(使用gradle,而不是maven)

hibernate spring-data spring-data-jpa spring-boot

44
推荐指数
3
解决办法
4万
查看次数

将Spring依赖项注入JPA EntityListener

我试图将Spring依赖注入到JPA EntityListener中.这是我的听众课程:

@Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true)
public class PliListener {

    @Autowired
    private EvenementPliRepository evenementPliRepository;

    @PostPersist
    void onPostPersist(Pli pli) {
        EvenementPli ev = new EvenementPli();
        ev.setPli(pli);
        ev.setDateCreation(new Date());
        ev.setType(TypeEvenement.creation);
        ev.setMessage("Création d'un pli");
        System.out.println("evenementPliRepository: " + evenementPliRepository);
        evenementPliRepository.save(ev);
    }


}
Run Code Online (Sandbox Code Playgroud)

这是我的Entity类:

@RooJavaBean
@RooToString
@RooJpaActiveRecord
@EntityListeners(PliListener.class)
public class Pli implements Serializable{
...
Run Code Online (Sandbox Code Playgroud)

但是,我的依赖(即evenementPliRepository)始终为null.

有人可以帮忙吗?

spring dependency-injection jpa spring-roo entitylisteners

43
推荐指数
12
解决办法
4万
查看次数