我正在使用org.springframework.orm.hibernate4.LocalSessionFactoryBean.LocalSessionFactoryBean并拥有以下类:
@Entity
@Table(name="ORDERS")
public class Order implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private long id;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn
private Item item;
...
}
和
@Entity
@Table(name="ITEM")
public class Item implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private long id;
private String img;
private long price;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn
private ItemCategory category;
private String description;
...
}
但是当服务器启动时,对于ORDERS表,没有创建外键:
mysql> desc ORDERS;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| item | tinyblob | YES | | NULL | |
| placedDate | datetime | YES | | NULL | |
| quantity | int(11) | NO | | NULL | |
| status | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
可能有什么不对?请建议。
谢谢
答案 0 :(得分:1)
通过将@OneToOne移到getter方法上来解决这个问题。
应该惩罚不耐烦,但任何人都可以告诉我为什么当注释在属性本身时它不起作用?
由于