【问题标题】:Differences between ActiveRecord and Repository when generating JPA entity from a database schema using Spring Roo?使用 Spring Roo 从数据库模式生成 JPA 实体时 ActiveRecord 和 Repository 之间的区别?
【发布时间】:2014-10-26 19:13:47
【问题描述】:

作为 Spring Roo 指导 here 在模式上执行 DBRE,我们有以下命令来生成实体及其相关文件。

我们可以在参数--activerecord 或--repository 之间进行选择;选择后者将忽略第一个。

我的问题是两者有什么区别?

roo> 数据库逆向工程师 --schema DbSchemaName --package ~.domain --activeRecord --存储库 --service --testAutomatically --enableViews --includeTables --excludeTables --includeNonPortableAttributes --disableVersionFields --disableGeneratedIdentifiers

使用 --activeRecord 选项创建“Active Record”实体 (如果未指定则默认)。

使用 --repository 选项创建 Spring Data JPA 存储库 每个实体。如果指定为 true,则 --activeRecord 选项为 忽略。

【问题讨论】:

    标签: jpa activerecord repository spring-roo dbref


    【解决方案1】:

    Roo 在http://docs.spring.io/spring-roo/docs/1.3.1.RC1/reference/html/base-layers.html#d4e1932 谈论这些模式

    Active Record Pattern

    • 活动记录模式是一种访问数据的方法 数据库。数据库表或视图被包装到一个类中。因此,一个 对象实例绑定到表中的单行。

    • 示例:持久化新实例(创建新行):

      Part part = new Part();
      part.name = "Sample part";
      part.price = 123.45;
      part.save();
      

    Repository pattern

    • 存储库在域和数据映射层之间进行调解,就像内存中的域对象集合一样。从概念上讲,存储库封装了持久化在数据存储中的一组对象以及对它们执行的操作,从而提供了持久层的更面向对象的视图。存储库还支持在域和数据映射层之间实现清晰分离和单向依赖的目标。

    • 示例:持久化新实例(创建新行):

      Part part = new Part(); 
      part.name = "Sample part"; 
      part.price = 123.45; 
      
      //RepositoryFactorySupport ;
      factory = ...; // Instantiate factory here or similar PartRepository 
      repository = factory.getRepository(PartRepository.class); 
      repository.save(part);
      

    【讨论】:

    • 请在您的回答中总结或引用相关内容以获得验证和接受。
    • Roo 参考指南没有阐明这些概念,我改进了我的答案。
    • 感谢您列出特定链接。我的 OP 询问差异,如果您已阅读建议的链接,请将您对发现的差异的摘要发送到此处。谢谢!
    • 我需要了解更多...虽然现在好多了。非常感谢!
    • Nam,你能按回答结束这个问题吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 2022-01-07
    • 2010-12-24
    • 2011-11-23
    • 1970-01-01
    • 2016-08-18
    相关资源
    最近更新 更多