作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
例如,当我们在@OneToMany 中使用mappedBy 注解时,我们是否提到了类名或表名?
一个例子:
@Entity
@Table(name = "customer_tab")
public class Customer {
@Id @GeneratedValue public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
private Integer id;
@OneToMany(mappedBy="customer_tab")
@OrderColumn(name="orders_index")
public List<Order> getOrders() { return orders; }
}
那么这两个哪个是正确的呢? :
谢谢!
最佳答案
两者都不正确。来自documentation :
mappedBy
public abstract java.lang.String mappedBy
The field that owns the relationship. Required unless the relationship is unidirectional.
mappedBy
注释表示它标记的字段由关系的另一方拥有,在您的示例中是一对多关系的另一方。我不确切知道你的模式是什么,但以下类定义是有意义的:
@Entity
@Table(name = "customer_tab")
public class Customer {
@OneToMany(mappedBy="customer")
@OrderColumn(name="orders_index")
public List<Order> getOrders() { return orders; }
}
@Entity
public class Order {
@ManyToOne
@JoinColumn(name = "customerId")
// the name of this field should match the name specified
// in your mappedBy annotation in the Customer class
private Customer customer;
}
关于java - mappedBy 指的是类名还是表名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38448019/
我是一名优秀的程序员,十分优秀!