PSQLException:错误:语法错误在或附近
2022-09-05 00:27:33
在JPA中,我有一种我认为是直截了当的关系。看起来像这样。公司集团:
@Entity
@Table
public class CompanyGroup implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
@Column(name = "name")
private String name;
@JoinColumn(name = "companies")
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Company> companies;
}
公司:
@Entity
@Table
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "name")
private String name;
@JoinColumn(name = "users")
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<User> users;
@Id
@GeneratedValue
private Long id;
}
用户:
@Entity
@Table
public class User {
@Column(name = "firstName")
private String firstName;
@Column(name = "lastName")
private String lastName;
@Column(name = "email")
private String email;
@Id
@GeneratedValue
private Long id;
}
我省略了二传手,获取器等。
这不起作用。我正在尝试将公司组(有2家公司,每个公司有2个用户,所有实体都是唯一的)保存到一个完全空的数据库中。
我使用Spring-Data来坚持这一点,在这样的服务中访问:
@Service
public class ConcreteCompanyGroupService implements CompanyGroupService {
@Autowired
private CompanyGroupRepository repository;
@Transactional
@Override
public void save(CompanyGroup group) {
repository.save(Collections.singleton(group));
}
}
当我尝试调用此方法时,我收到以下消息:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "User"
Position: 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291)
希望我做了一些愚蠢的事情,有人可以很快找到。我不知道如何解决这个问题。
编辑:
我pom中的司机.xml:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211</version>
</dependency>