开发者

Many to one entity using JPA

I am trying to create an entity for the table structure given belos

(id, name, task, leader_id)

this table gives the information about the team users for the particular task and their leader for the team.

I wrote the entity like this

@Column(name = "id", insertable = false, nullable = false, updatable = true)
private Integer id;

@Col umn(name = "name", nullable = false)
private String tokenName;

@Column(name = "task", nullable = false)
private String task;

@ManyToOne(cascade = ALL, fetch = LAZY)
@JoinColumn(name = "leader_id")
private User leader;

I created the ddl through hibernate3:hbm2ddl and it looks like this

alter table user
drop
foreign key FK60FD5D6395C4EEC2;

drop table if exists user;

create table user (
    id integer not null auto_increment,
    task varchar(255),
    name varchar(255) not null,
    leader_id integer,
    primary key (id)
);

alter table user
    add index FK60FD5D6395C4EEC2 (leader_id),
    add const开发者_运维问答raint FK60FD5D6395C4EEC2
    foreign key (leader_id)
    references user (id);

while exporting this schema through maven-sql-plugin, I am getting the following error

[ERROR] Failed to execute:
alter table user
drop
foreign key FK60FD5D6395C4EEC2
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Column "FOREIGN" not found; SQL statement:

alter table user
drop
foreign key FK60FD5D6395C4EEC2 [42122-158]

Where I am doing wrong?


Try this:

@ManyToOne(cascade = ALL, fetch = LAZY)
@JoinColumn(name = "leader_id")
@NotFound(action = NotFoundAction.IGNORE) 
public User getLeader()
{
  return leader;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜