我正在使用spring数据jpa,hibernate,mysql,tomcat7,maven开发应用程序,这就是创建错误.我想弄明白但是我失败了.
错误是在设置构造函数参数时无法解析对bean'entalManagerFactory'的引用; 没有定义名为'entityManagerFactory'的bean; 注入自动连接的依赖项失败
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initDbService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.wahid.cse.repository.RoleRepository org.wahid.cse.service.InitDbService.roleRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Cannot create inner bean '(inner bean)#c08f81' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#c08f81': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' …
Run Code Online (Sandbox Code Playgroud) 我有三个实体:EntityA、EntityB 和 EntityC。我需要使用 spring data jpa 从这些实体中将连接查询的值获取到对象列表中。查询是:
select x.id,x.formNo,x.name, z.testScore, y.semester
from EntityA as x left join EntityB as z on x.id = z.a_id
inner join EntityC as y on x.c_id = y.id where x.id=1
Run Code Online (Sandbox Code Playgroud)
这些实体是:
实体A:
@Entity
public class EntityA {
@Id
@GeneratedValue
private Integer id;
private String name;
private String formNo;
@OneToOne(mappedBy = "a",fetch=FetchType.LAZY, cascade = CascadeType.REMOVE)
private EntityB b;
@ManyToOne
@JoinColumn(name = "EntityC_id")
private EntityC c;
}
Run Code Online (Sandbox Code Playgroud)
实体B:
@Entity
public class EntityB {
@Id
@GeneratedValue
private Integer …
Run Code Online (Sandbox Code Playgroud) 结果sql应该是:
"SELECT * FROM items where id LIKE '%"+ key + "%' or name LIKE '%"+ key + "%'";
Run Code Online (Sandbox Code Playgroud)
这里的键是变量.我需要在spring数据jpa中执行此sql.
我尝试如下,代码不起作用
@Transactional
public List<Item> findItemNameOrId(String key) {
return itemRepository.findByItemNameOrIdContaining(key);
}
Run Code Online (Sandbox Code Playgroud)
这是ItemRepository
public interface ItemRepository extends JpaRepository<Item, Integer> {
List<Item> findByItemNameOrIdContaining(String key);
}
Run Code Online (Sandbox Code Playgroud)