提问人:AylaWinters 提问时间:1/23/2023 最后编辑:AylaWinters 更新时间:1/23/2023 访问量:257
Amazon Redshift 无效操作:列表示法 .id 应用于类型字符,该字符不是复合类型;Spring Data JPA
Amazon Redshift Invalid operation: column notation .id applied to type character, which is not a composite type; Spring Data JPA
问:
我在尝试从 Amazon Redshift 数据库中提取时遇到错误,但不知道如何修复它。
错误:
com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation:
column notation .id applied to type character, which is not a composite type;
application.properties:
spring.jpa.show-sql=true
spring.datasource.url=jdbc:redshift://mydb.blah.region.redshift.amazonaws.com:5439/dev?currentSchema=myschema
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.dbcp2.validation-query=SELECT 1
控制器:
@RestController
@RequestMapping("/")
public class ContactController {
private RedshiftRepo repo;
@Autowired
public ContactController(RedshiftRepo repo) {
this.repo = repo;
}
@GetMapping(value = "/get")
public ResponseEntity<List<Contact>> getTest(){
List<Contact> list = repo.findAll();
return new ResponseEntity<List<Contact>>(list, HttpStatus.OK);
}
@GetMapping(value = "/getByEmail")
public ResponseEntity<List<Contact>> getByEmail(@RequestParam String email){
List<Contact> list = repo.getContactByEmail(email);
return new ResponseEntity<List<Contact>>(list, HttpStatus.OK);
}
}
Redshift存储库:
@Repository
public interface RedshiftRepo extends JpaRepository<Contact, Integer>{
@Query("select id, firstname, lastname, accountid from Contact c where c.email = ?1")
public Contact getContactByEmail(String email);
}
实体:
@Entity
@Table(name ="user")
public class Contact {
@Id
private String id;
private String firstname;
private String lastname;
private String accountid;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.contactAPI</groupId>
<artifactId>pocContactAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pocContactAPI</name>
<description>Contact Getter</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-redshift</artifactId>
<version>1.11.999</version>
</dependency>
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.41.1065</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>redshift</id>
<url>http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
当我尝试获取localhost:8080 / get时:
Hibernate: select c1_0.id,c1_0.firstname,c1_0.lastname,c1_0.accountid from user c1_0
com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation:
column notation .id applied to type character, which is not a composite type;
知道我做错了什么吗?
答:
0赞
PCDSandwichMan
1/23/2023
#1
您需要向 pom.xml 添加以下依赖项:
(据我所知,您已经完成了第一步,但是我也将其包括在其他人中。
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.41.1065</version>
</dependency>
这将允许您使用 Redshift JDBC 驱动程序。您可以在此处找到有关此内容的更多信息:https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html
您还需要在 application.properties 中指定 Redshift 驱动程序:
spring.datasource.driver-class-name=com.amazon.redshift.jdbc42.Driver
您可以在此处找到有关此内容的更多信息:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto-initialize-a-database-using-spring-jdbc
进行这些更改后,我能够运行您的应用程序并获得以下响应:
[
{
"id": "1",
"firstname": "John",
"lastname": "Doe",
"accountid": "1"
}
]
我希望这会有所帮助!
评论
0赞
AylaWinters
1/23/2023
感谢您提供的信息,我确实有第一个,我添加了第二个,但我仍然遇到同样的错误。难道我还忘记了什么吗?谢谢
0赞
PCDSandwichMan
1/24/2023
非常有趣,您是否能够共享指向存储库的链接,或者代码库是私有的?
0赞
AylaWinters
1/24/2023
不幸的是,代码库是私有的(用于工作)
0赞
PCDSandwichMan
1/25/2023
好的,不用担心。我将更多地使用它,看看我是否可以以另一种方式重新创建错误。
1赞
AylaWinters
1/25/2023
谢谢,为了知识的缘故和将来发现这一点的任何人知道会很好,但我的工作只是改变了我将使用的架构/表,并且在访问它们时没有遇到这个问题。可能是“用户”可能是一个系统表,或者如上面发布的那样无法使用@Neeraj。再次感谢您的帮助!
评论
@Table(name ="user")
@Table(name = "TABLE1", schema="test")