标签: spring-data

在spring-data项目中使用@Version

我一直在使用带有spring-data的RESTful web服务.几天前,发布了一个特殊的spring-data jpa REST框架.

现在我注意到在这个框架中使用@Version的能力.此版本是由自己生成还是您需要手动执行此操作?

它可以自己使用@Version吗?(这样我就不必将任何内容更改为现有的存储库/域等...)

我是否需要做一些额外的配置才能使用@Version?

java hibernate spring-data spring-data-jpa spring-data-rest

30
推荐指数
2
解决办法
2万
查看次数

在Spring Data JPA存储库中使用泛型

我有许多简单的对象类型需要持久化到数据库.我正在使用Spring JPA来管理这种持久性.对于每个对象类型,我需要构建以下内容:

import org.springframework.data.jpa.repository.JpaRepository;

public interface FacilityRepository extends JpaRepository<Facility, Long> {
}


public interface FacilityService {
    public Facility create(Facility facility);
}

@Service
public class FacilityServiceImpl implements FacilityService {

    @Resource
    private FacilityRepository countryRepository;

    @Transactional
    public Facility create(Facility facility) {
        Facility created = facility;
        return facilityRepository.save(created);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想到有可能用三个基于泛型的类替换每个对象类型的多个类,从而节省了大量的样板编码.我不确定如何去做,事实上如果这是一个好主意?

java spring jpa spring-data spring-data-jpa

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

带JPA的Spring Boot:将@Entity移动到不同的包

我在使用带JPA的Spring-Boot的第一步时遇到了麻烦.我从Git使用Gradle的一个非常简约的例子开始.

现在只需转移Customer到另一个包,让我们说hello2结果是异常Caused by: java.lang.IllegalArgumentException: Not an managed type: class hello2.Customer.我试着补充一下

@ComponentScan(basePackageClasses= {Customer.class}) // AND OR @EnableJpaRepositories(basePackageClasses= {Customer.class})

Application,但没有成功.

我究竟做错了什么?

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

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

为什么Spring在一台机器而不是另一台机器上获得循环依赖性问题?

我在使用基于Spring Data的应用程序在我的环境中运行时遇到了问题.我正在运行Debian,但我的同事正在使用Mac或Ubuntu.我的环境变量中没有任何特殊设置,并且使用与其他版本完全相同的Java版本.

我在日志中看到过这一点,这表明它是一个循环引用问题导致实例化失败:

nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'flyway.CONFIGURATION_PROPERTIES':
Initialization of bean failed;
...
nested exception is
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'flyway': Requested bean is currently in
creation: Is there an unresolvable circular reference?
Run Code Online (Sandbox Code Playgroud)

所以问题似乎是飞路需要一些依赖,他们需要飞路.

问题是,为什么这只发生在我的环境而不是任何人?即使在内存中使用H2的测试中,我也看到了问题,因此不是我的数据库出错了.

是否有可能以某种方式混淆Spring自动装配,并尝试以错误的顺序执行操作,以便在尝试设置存储库时为null?

Spring是否有一个严重实现的拓扑排序用于排序依赖项?

为什么它会对我的环境造成不良影响?

类路径的排序会影响它的行为吗?

======================

应用程序不会以此错误开头:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentItemRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Repository interface must not be null on initialization!
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:127)
    at …
Run Code Online (Sandbox Code Playgroud)

java spring dependency-injection spring-data

29
推荐指数
3
解决办法
9266
查看次数

Spring Data JPA:查询ManyToMany

我有实体UserTest

@Entity
public class User {
    private Long id;
    private String userName;
}

@Entity
public class Test {
    private Long id;

    @ManyToMany
    private Set<User> users;
}
Run Code Online (Sandbox Code Playgroud)

我可以通过用户实体获得所有测试:

public interface TestRepository extends JpaRepository<EventSettings, Long> {
    List<Test> findAllByUsers(User user);
}
Run Code Online (Sandbox Code Playgroud)

但是我可以使用哪个查询来查找所有测试userName

java spring jpa spring-data spring-data-jpa

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

如何在Spring Mvc Jpa中将enity对象的List转换为Page对象?

我有一个List实体.如何Page使用Spring MVC 4和Spring Data JPA 将其转换为Object?

java pagination spring-mvc spring-data

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

Spring CRUD存储库:有没有findOneByMaxXYZColumn()?

我的要求:

如果VERSION列具有最大值,则从表RETAIN_INFO中获取ONE对象(例如RetainInfo)

CRUD存储库是否支持类似的接口方法

findOneByMaxRetVersionAndCountry("DEFAULT")
Run Code Online (Sandbox Code Playgroud)

等价的db2 sql:

select RET_ID, max(ri.RET_VERSION) from RETAIN_INFO ri  where ri. COUNTRY='DEFAULT'  group by RET_ID  fetch first 1 rows only;
Run Code Online (Sandbox Code Playgroud)
  • 此查询选择一个ID,但我实际上希望RetainInfo对象对应于查询返回的SINGLE行.

我更喜欢不使用自定义查询,即使用findBy或Spring CRUD支持的其他方法/接口.

spring-data

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

Spring启动 - Application.properties中的自定义变量

我有弹簧启动客户端,消耗一个宁静的API.而不是在java类中硬编码REST API的IP地址,我可以使用application.properties中的任何键入口吗?

如果没有,我可以创建自定义条目吗?

谢谢

spring spring-mvc spring-data spring-boot

28
推荐指数
2
解决办法
5万
查看次数

如何在使用带有弹簧数据的MongoRepository的查询注释时显示查询

我在spring boot中使用MongoRepository来访问mongo:

public interface MongoReadRepository extends MongoRepository<User, String> {
    @Query(value = "{$where: 'this.name == ?0'}", count = true)
    public Long countName(String name);
}
Run Code Online (Sandbox Code Playgroud)

它可以工作,但我想知道它访问mongo的确切查询

怎么做?

我尝试在下面的属性添加一些配置:

logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
logging.level.org.springframework.data.mongodb.repository.Query=DEBUG
Run Code Online (Sandbox Code Playgroud)

并且不工作.

有人可以帮忙吗?

java spring mongodb spring-data mongorepository

28
推荐指数
4
解决办法
2万
查看次数

spring mongo数据存储库接口的"无效十六进制表示"

我有一个存储库接口,如下所示:

public interface ExcursionAttendeeRepository extends MongoRepository<ExcursionAttendee, String> {

    ExcursionAttendee findByWorkflowItemId(String workflowItemId);

    @Query("{ 'excursionEvent._id' : { '$oid' : ?0 } }")
    List<ExcursionAttendee> findByExcursionId(String excursionId);

    @Query("{ 'student._id' : {'$oid' : ?0} , 'excursionEvent._id' : { '$oid' : ?1 } }")
    ExcursionAttendee findByStudentIdAndEventId(String studentId, String excursionId);

    @Query("{ 'student._id' : { '$oid' : ?0 } }")
    List<ExcursionAttendee> findByStudentId(String studentId);
}
Run Code Online (Sandbox Code Playgroud)

而Bean创建spring则抛出异常.

Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0.1':
  Cannot create inner bean '(inner bean)#5172829b' of type [org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter] while setting bean property …
Run Code Online (Sandbox Code Playgroud)

mongodb spring-data spring-data-mongodb

28
推荐指数
1
解决办法
1197
查看次数