我有两个实体:Account
& Transaction
。
一个帐户可以有很多交易,一个交易可能会受到许多帐户的影响。
这是实体类:
@Entity
public class Account {
private Long id;
...
private List<Transaction> transactions;
...
private Double deferredAmmount;
public Account() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToMany(cascade = CascadeType.ALL)
public List<Transaction> getTransactions() {
return transactions;
}
public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}
@Formula("(SELECT SUM(transaction.amount) FROM transaction LEFT JOIN account_transaction ON( account_transaction.transactions_id = transaction.id) LEFT JOIN account ON (account_transaction.Account_id = account.id) where account.id = id)")
public Double getDeferredAmmount() {
return deferredAmmount;
}
public void setDeferredAmmount(Double deferredAmmount) {
this.deferredAmmount = deferredAmmount;
}
}
表account_transaction
由@ManyToMany
注释创建。我有这个例外
MySQLSyntaxErrorException: Table 'account0_.account_transaction' doesn't exist.
你对这个问题有所了解吗?
谢谢。
答案 0 :(得分:2)
这意味着在您的数据库中没有表&#39; account0_.account_transaction&#39;。 您可以手动创建它或更改persistence.xml设置(hibernate.hbm2ddl.auto)以允许Hibernate为您创建它。
如果您不希望从字段名称中获取名称,则可以使用@JoinTable注释明确指定名称。