[英]JpaRepository database connection error on @query the table showing red
Help me masters... i keep got error Cant resolve symbol on my JpaRepository帮我大师...我一直有错误无法解析我的 JpaRepository 上的符号
Query @Query(value="SELECT i FROM AkunIpaddressEnt i ORDER BY i.ID DESC")查询@Query(value="SELECT i FROM AkunIpaddressEnt i ORDER BY i.ID DESC")
the word "AkunIpaddressEnt" query my query showing red iam sure everything is on the right place, am using intelij spring-boot JpaRepository “AkunIpaddressEnt”这个词查询我的查询显示红色我确定一切都在正确的地方,我正在使用 intelij spring-boot JpaRepository
my repository我的仓库
@Repository
@Transactional("dbilapTransactionManager")
public interface AkunIpaddressRepo extends JpaRepository<AkunIpaddressEnt,Integer> {
@Query(value="SELECT i FROM AkunIpaddressEnt i ORDER BY i.ID DESC")
List<AkunIpaddressEnt> getlistIPaddress();
}
my entity我的实体
@Data
@Entity
@Table(name="AKUN_IPADDRESS")
public class AkunIpaddressEnt {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AKUNIPADRESSSEQUENCE")
@SequenceGenerator(sequenceName = "AKUNIPADRESSSEQUENCE", allocationSize = 1, name = "AKUNIPADRESSSEQUENCE")
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
my configuration我的配置
@Configuration
@PropertySource({"classpath:application.properties"})
@EnableJpaRepositories(
basePackages = "com.repository.dbilap",
entityManagerFactoryRef = "dbilapEntityManager",
transactionManagerRef = "dbilapTransactionManager")
public class DbConDBILAP {
@Autowired
private Environment env;
@Bean
public DataSource DbilapDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("datasource2.driverClassName"));
dataSource.setUrl(env.getProperty("datasource2.url"));
dataSource.setUsername(env.getProperty("datasource2.username"));
dataSource.setPassword(env.getProperty("datasource2.password"));
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean dbilapEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(DbilapDataSource());
em.setPackagesToScan(
new String[] { "com.entity.dbilap" });
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect",
env.getProperty("datasource2.hibernate.dialect"));
properties.put("show.sql",
env.getProperty("datasource2.hibernate.show.sql"));
em.setJpaPropertyMap(properties);
return em;
}
@Bean
public PlatformTransactionManager dbilapTransactionManager() {
JpaTransactionManager transactionManager
= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
dbilapEntityManager().getObject());
return transactionManager;
}
}
my properties我的属性
datasource2.url=jdbc:oracle:thin:@0.0.0.0:1521:DBILAP
datasource2.username=MYUSERNAME
datasource2.password=MYPASSWORD
datasource2.driverClassName=oracle.jdbc.OracleDriver
datasource2.hibernate.dialect=org.hibernate.dialect.Oracle8iDialect
datasource2.hibernate.show.sql=true
whats wrong?怎么了?
Queries in Spring Data should reference entity name and property names, instead of table name and column names. Spring Data 中的查询应该引用实体名称和属性名称,而不是表名称和列名称。
So, your query should be:所以,你的查询应该是:
@Query(value="SELECT i FROM AkunIpaddressEnt i ORDER BY i.id DESC")
Instead of:代替:
@Query(value="SELECT i FROM AKUN_IPADDRESS i ORDER BY i.ID DESC")
Also remove the (name="dbilapEntityManager") of your Entity because you are overriding the entity name expected in the queries with a name that is not related with the entity itself.还要删除实体的 (name="dbilapEntityManager"),因为您正在使用与实体本身无关的名称覆盖查询中预期的实体名称。
Finally in the @Table you should use the "name" attribute instead of the "schema" attribute to define the table name.最后在@Table 中,您应该使用“name”属性而不是“schema”属性来定义表名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.