3
我有我認爲是JPA中的一個簡單的關係。看起來像這樣。 CompanyGroup:PSQLException:錯誤:語法錯誤在或接近
@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;
}
我省略setter方法,getter方法等
這是行不通的。我試圖將一個CompanyGroup(有兩家公司,每家公司有兩個用戶,所有實體都是唯一的)保存到一個完全空的數據庫中。
我堅持這一點使用Spring的數據,在服務訪問是這樣的:
@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>
似乎與以下內容相同:http://stackoverflow.com/questions/3608420/hibernate-saving-user -model到的Postgres –