Tag: repository

DDD(java)聚合根和持久性

我正在创建一个应用程序,它将使用各种大小的表格,而我已经开发了一个标记为DDD的项目,之后它没有真正使持久性部分正确,因此我还在研究事物。 我没有完全掌握并且似乎无法找到具体例子的一件事是如何坚持聚集根的“孩子”。 我工作时没有ORM(只是普通的老DAO)很难找到的例子(这实际上是针对uni的项目,这是db特定的所以我’不允许’使用ORM,而我很欣赏这简直太容易了。 我已经四处查看了stackoverflow的具体示例,但似乎没有什么能够描述我的特定问题。 我怀疑下面的代码是对的 public DataTable getTableByID(int id) throws AccessException{ DataTable result = this.context.TableContext().getEntityByID(id); result.setColumns(getColumnsByTableID(id)); return result; } private List getColumnsByTableID(int id){ Object[] arguments = { id }; return this.context.ColumnContext().getUnitsWhere(“TABLE_ID = ?”, arguments); } 如您所见,每次检索表实体时都会设置columns集合,如果表已经在内存中,这显然会丢弃已添加到集合中或从集合中删除的任何列。 我不确定我应该在哪里或如何检索列(我已经考虑过从表类中调用存储库但是对此感觉不舒服)。 说到持久性,我也不完全确定如何去做,当我将对象添加到列表中时我可以很容易地检索它们但是当我删除它们时我真的没有办法检测(因为我是确保把事件赶上来这将是作弊:))。 非常感谢,向正确的方向推进一点点,谢谢。

gradle存储库指向具有多个库的本地目录

我对本地存储库的build.gradle中的构建依赖关系有疑问(即使用本地目录) dependencies { compile fileTree(include: [‘*.jar’], dir: ‘libs’) } 它是仅解决了libs目录中的依赖关系还是解析了lib目录的所有子文件夹的依赖关系? 如果它不解析子文件夹/子目录的依赖关系,如何解决依赖关系? 注意:我们的项目依赖于大量的jar文件(而不是为每个jar / libs提供完整的文件名),所以想知道任何替代方式。

无法在Junit测试中自动assemblyJpaRepository – Spring启动应用程序

大家好 我正在尝试在Spring启动应用程序中执行Junit测试,Junit应该测试一些CRUD操作,我正在使用Spring Repositories专门使用JpaRepository。 存储库calss: package au.com.bla.bla.bla.repository; import org.springframework.data.jpa.repository.JpaRepository; import au.com.bla.bla.bla.entity.Todo; public interface TodoRepository extends JpaRepository { } TodoController类 package au.com.bla.bla.bla.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import au.com.bla.bla.bla.entity.Todo; import au.com.bla.bla.bla.repository.TodoRepository; import java.util.List; import java.util.Map; @RestController @CrossOrigin public class TodoController { static final String TEXT = “text”; @Autowired […]

多个存储库的Maven设置

我在settings.xml中有以下内容 paid-jars jars with license http://url:8081/nexus/content/repositories/paidjars/ !central Org-central mirror of central http://url:8081/nexus/content/repositories/central/ central 在pom.xml中我有两个jar子 apache-commons.jar(我假设从中心下载) licensed.jar(我假设从付费jar子下载) 但是当我运行maven clean install它会尝试从Org-central下载licensed.jar。 如何让它使用付费jar子下载? 是否有可能首先进入Org-central,如果失败,它会尝试付费jar子? 如果是这样,怎么样? 我不想把repo条目放在pom.xml中 将Settings.xml Proxy true http username ****** host.url 8080 local.net|internal.com paid-jars jars with license http://url:8081/nexus/content/repositories/paidjars/ !central Org-central mirror of central http://url:8081/nexus/content/repositories/central/ central compiler C:\Program Files (x86)\Java\jdk1.7.0_51\bin

什么是@Repository和@Autowired用于。 (弹簧)

我正在学习java 3个月,有时我无法理解某些东西的使用目的。 一个主题是dependency injection和spring bean我想出了finally =) 现在我混淆了两个注释@Autowired和@Repository。 首先Autowiring是什么意思? 然后我为什么要使用它们,使用它们和不使用它们之间有什么区别? 今天我也尝试在spring mvc项目中使用hibernate,我不得不搜索大约15个(类找不到错误的原因)jar文件,因为项目中使用的其他jar文件的依赖项。 这是不是必须这样? 这使得初学者学习java非常困难 谢谢…

是什么意思 save(S entity); 在Spring Repository中?

在Spring Data项目中,CrudRepository为正在管理的实体类提供了复杂的CRUDfunction。 public interface CrudRepository extends Repository { S save(S entity); T findOne(ID primaryKey); Iterable findAll(); Long count(); void delete(T entity); boolean exists(ID primaryKey); // … more functionality omitted. } 一般来说,我知道“S extends T”意味着什么,即S,保存操作的返回类型,必须是T的子类型。为什么有必要添加诸如约束? 我认为做这样的事情会很好: T save (T entity); 如在 void delete(T entity); 我已经用谷歌搜索了更多的帮助,我已经在stackoverflow本身上找到了以下问题,但对我来说并不是很清楚: Spring CrudRepository:为什么要发明一个新的generics类型S. 谢谢。

NoSuchBeanDefinitionException:没有为依赖项找到类型的限定bean:预期至少有1个bean有资格作为autowire

我发现类似的问题解释了很多门户网站。 但我想这是独特的情况。 我在spring mvc app中收到错误。 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘testController’ defined in file [C:\Program Files (x86)\sts-bundle\pivotal-tc-server-developer-3.1.2.RELEASE\base-instance\wtpwebapps\ExpT1\WEB-INF\classes\com\expt\controller\TestController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.expt.repositories.CategoryRepository]: No qualifying bean of type [com.expt.repositories.CategoryRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; […]

声明式事务(@Transactional)不适用于Spring中的@Repository

我正在尝试使用Spring,JPA和嵌入式H2数据库进行简单的应用程序。 最近我遇到了声明性交易这个奇怪的问题。 如果我使用@Repository注释自动assembly我的DAO,它们就不会提交。 更具体地说,我在flush上获得exception: javax.persistence.TransactionRequiredException: Exception Description: No transaction is currently active 这是我的设置: persistence.xml中 org.eclipse.persistence.jpa.PersistenceProvider false 实体 @Entity @Table(name = “Professors”) public class Professor { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; public Professor() { } public Professor(String name) { this.name = name; } } DAO @Repository public class JpaDao { @PersistenceContext […]

如何使用Join定义JPA存储库查询

我想使用带有注释@Query的Jpa存储库进行Join查询。 我有两张桌子: table user with iduser,user_name 和: table area with idarea, area_name and iduser 原生查询是: SELECT u.user_name FROM user as u INNER JOIN area as a ON a.iduser = u.iduser WHERE a.idarea = 4 现在我有一个表Hibernate实体用户和区域 所以我尝试使用UserRespository @Query(SELECT u.userName FROM User u INNER JOIN Area a ON a.idUser = u.idUser WHERE a.idArea = :idArea) List findByIdarea(@Param(“idArea”) […]

Spring-Data-Jpa存储库 – 实体列名称的下划线

我在spring webmvc项目中使用spring-data-jpa。 我在我的一个实体的存储库上使用查询创建时遇到了问题。 您可以在下面看到我的实体,我的存储库和exception。 我的实体, @Entity @Table(schema = “mainschema”) @XmlRootElement public class Municipalperson implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(nullable = false) private Integer id; @Basic(optional = false) @Column(name = “municipal_id”, nullable = false) private Integer municipal_id; @Basic(optional = false) @Column(nullable = false, length […]