0

我正在使用 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)

有什么问题?请建议。

谢谢

4

1 回答 1

1

通过将 @OneToOne 移到 getter 方法上解决了这个问题。

不耐烦应该受到惩罚,但是谁能告诉我为什么当注释在属性本身上时它不起作用?

谢谢

于 2013-07-08T02:35:58.620 回答