package com.test.ioc;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;
@Table("tb_idcard")
public class IdCard {
@Id
private long id;
@Column
private String carNo;
private User user;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCarNo() {
return carNo;
}
public void setCarNo(String carNo) {
this.carNo = carNo;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
package com.test.ioc;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.One;
import org.nutz.dao.entity.annotation.Table;
@Table("tb_user1")
public class User {
@Id
private long id;
@Name
@Column
private String name;
@One(field = "cardId")
private IdCard a;
@Column
private long cardId;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public IdCard getA() {
return a;
}
public void setA(IdCard a) {
this.a = a;
}
public long getCardId() {
return cardId;
}
public void setCardId(long cardId) {
this.cardId = cardId;
}
}
貌似上面这样写是单向的 从user可以找到idcard,从idcard不能找到user啊
IdCard idCard = dao.fetch(IdCard.class, 1);
dao.fetchLinks(idCard, "user");
System.out.println(idCard.getUser().getName());这样写报空指针异常。。,用user是可以的!!,请问怎么解决这种双向 我在private User user;加上one(field="cardId")的时候就报错了!!