遇到一个奇怪的问题希望达人能解释一下.在bean中配置数据加载模式为延迟加载,在去port时却执行两条select语句:
Hibernate: select port0_.portID as portID44_0_, port0_.airFlag as airFlag44_0_, port0_.createDate as createDate44_0_, port0_.createOpr as createOpr44_0_, port0_.disable as disable44_0_, port0_.englishName as englishN6_44_0_, port0_.modifyDate as modifyDate44_0_, port0_.modifyOpr as modifyOpr44_0_, port0_.nationID as nationID44_0_, port0_.notes as notes44_0_, port0_.othersFlag as othersFlag44_0_, port0_.portCode as portCode44_0_, port0_.portName as portName44_0_, port0_.seaFlag as seaFlag44_0_, port0_.version as version44_0_ from global_config_port port0_ where port0_.portID=?Hibernate: select nation0_.nationID as nationID41_0_, nation0_.airLaneID as airLaneID41_0_, nation0_.createDate as createDate41_0_, nation0_.createOpr as createOpr41_0_, nation0_.disable as disable41_0_, nation0_.englishName as englishN5_41_0_, nation0_.iataArea as iataArea41_0_, nation0_.modifyDate as modifyDate41_0_, nation0_.modifyOpr as modifyOpr41_0_, nation0_.nationCode as nationCode41_0_, nation0_.nationName as nationName41_0_, nation0_.nationShort as nationS11_41_0_, nation0_.noWood as noWood41_0_, nation0_.notes as notes41_0_, nation0_.seaLaneID as seaLaneID41_0_, nation0_.version as version41_0_ from global_config_nation nation0_ where nation0_.nationID=?
如果使用Hibernate默认设置(Hibernate3默认设置是延迟加载),结果只执行一条select语句:
Hibernate: select port0_.portID as portID44_0_, port0_.airFlag as airFlag44_0_, port0_.createDate as createDate44_0_, port0_.createOpr as createOpr44_0_, port0_.disable as disable44_0_, port0_.englishName as englishN6_44_0_, port0_.modifyDate as modifyDate44_0_, port0_.modifyOpr as modifyOpr44_0_, port0_.nationID as nationID44_0_, port0_.notes as notes44_0_, port0_.othersFlag as othersFlag44_0_, port0_.portCode as portCode44_0_, port0_.portName as portName44_0_, port0_.seaFlag as seaFlag44_0_, port0_.version as version44_0_ from global_config_port port0_ where port0_.portID=?注解包使用的是:
import javax.persistence.ManyToOne;
难道在Hibernate配置还有负负得正的关系嘛~
下面是bean代码:
@Entity
@Table(name="global_config_port" )
public class Port extends BaseEntity { @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer portID;
private String portCode;
private String portName;
private String englishName;
@ManyToOne(fetch=FetchType.LAZY)//这里显示声明为延迟加载
@NotFound(action=NotFoundAction.IGNORE)
@JoinColumn(name="nationID")
private Nation nation;
private Boolean airFlag;
private Boolean seaFlag;
private Boolean othersFlag;
private String notes;
private Boolean disable;
private String createOpr;
private Date createDate;
private String modifyOpr;
private Date modifyDate;
@Version
private Long version;
public Port(Integer portID,Long version) {
super();
this.portID = portID;
this.version = version;
}
public Port() {
super();
}
@Override
public Map<String, Object> describe() {
Map<String,Object> map = ListOrderedMap.decorate(new CaseInsensitiveMap());
map.put("portID", getPortID());
map.put("portCode", getPortCode());
map.put("portName", getPortName());
map.put("englishName", getEnglishName());
// map.put("nationID", getNation().getNationID());//这里已经把取关联数据注释掉了
map.put("airFlag", getAirFlag());
map.put("seaFlag", getSeaFlag());
map.put("othersFlag", getOthersFlag());
map.put("notes", getNotes());
map.put("disable", getDisable());
map.put("createOpr", getCreateOpr());
map.put("createDate", getCreateDate());
map.put("modifyOpr", getModifyOpr());
map.put("modifyDate", getModifyDate());
map.put("version", getVersion());
return map;
}}
Hibernate: select port0_.portID as portID44_0_, port0_.airFlag as airFlag44_0_, port0_.createDate as createDate44_0_, port0_.createOpr as createOpr44_0_, port0_.disable as disable44_0_, port0_.englishName as englishN6_44_0_, port0_.modifyDate as modifyDate44_0_, port0_.modifyOpr as modifyOpr44_0_, port0_.nationID as nationID44_0_, port0_.notes as notes44_0_, port0_.othersFlag as othersFlag44_0_, port0_.portCode as portCode44_0_, port0_.portName as portName44_0_, port0_.seaFlag as seaFlag44_0_, port0_.version as version44_0_ from global_config_port port0_ where port0_.portID=?Hibernate: select nation0_.nationID as nationID41_0_, nation0_.airLaneID as airLaneID41_0_, nation0_.createDate as createDate41_0_, nation0_.createOpr as createOpr41_0_, nation0_.disable as disable41_0_, nation0_.englishName as englishN5_41_0_, nation0_.iataArea as iataArea41_0_, nation0_.modifyDate as modifyDate41_0_, nation0_.modifyOpr as modifyOpr41_0_, nation0_.nationCode as nationCode41_0_, nation0_.nationName as nationName41_0_, nation0_.nationShort as nationS11_41_0_, nation0_.noWood as noWood41_0_, nation0_.notes as notes41_0_, nation0_.seaLaneID as seaLaneID41_0_, nation0_.version as version41_0_ from global_config_nation nation0_ where nation0_.nationID=?
如果使用Hibernate默认设置(Hibernate3默认设置是延迟加载),结果只执行一条select语句:
Hibernate: select port0_.portID as portID44_0_, port0_.airFlag as airFlag44_0_, port0_.createDate as createDate44_0_, port0_.createOpr as createOpr44_0_, port0_.disable as disable44_0_, port0_.englishName as englishN6_44_0_, port0_.modifyDate as modifyDate44_0_, port0_.modifyOpr as modifyOpr44_0_, port0_.nationID as nationID44_0_, port0_.notes as notes44_0_, port0_.othersFlag as othersFlag44_0_, port0_.portCode as portCode44_0_, port0_.portName as portName44_0_, port0_.seaFlag as seaFlag44_0_, port0_.version as version44_0_ from global_config_port port0_ where port0_.portID=?注解包使用的是:
import javax.persistence.ManyToOne;
难道在Hibernate配置还有负负得正的关系嘛~
下面是bean代码:
@Entity
@Table(name="global_config_port" )
public class Port extends BaseEntity { @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer portID;
private String portCode;
private String portName;
private String englishName;
@ManyToOne(fetch=FetchType.LAZY)//这里显示声明为延迟加载
@NotFound(action=NotFoundAction.IGNORE)
@JoinColumn(name="nationID")
private Nation nation;
private Boolean airFlag;
private Boolean seaFlag;
private Boolean othersFlag;
private String notes;
private Boolean disable;
private String createOpr;
private Date createDate;
private String modifyOpr;
private Date modifyDate;
@Version
private Long version;
public Port(Integer portID,Long version) {
super();
this.portID = portID;
this.version = version;
}
public Port() {
super();
}
@Override
public Map<String, Object> describe() {
Map<String,Object> map = ListOrderedMap.decorate(new CaseInsensitiveMap());
map.put("portID", getPortID());
map.put("portCode", getPortCode());
map.put("portName", getPortName());
map.put("englishName", getEnglishName());
// map.put("nationID", getNation().getNationID());//这里已经把取关联数据注释掉了
map.put("airFlag", getAirFlag());
map.put("seaFlag", getSeaFlag());
map.put("othersFlag", getOthersFlag());
map.put("notes", getNotes());
map.put("disable", getDisable());
map.put("createOpr", getCreateOpr());
map.put("createDate", getCreateDate());
map.put("modifyOpr", getModifyOpr());
map.put("modifyDate", getModifyDate());
map.put("version", getVersion());
return map;
}}
解决方案 »
- Eclipse、JBoss、SQL2005 开发EJB3.0 但连接不上数据库请高手指点
- 部署的项目404
- 谁有 vsflexgrid8 cab ??? 急 急 急
- struts2+spring+hibernate 中AOP的一个问题?不加事务只可以读数据,,不能写,后台不报错,加了事务读也报错,求指教,不胜感谢
- struts2.0.9利用ajax验证表单数据时,页面无法正常跳转问题,急!
- Struts+Jfreechart 从数据库取数据画曲线
- 一个Web Application中数据库连接的获取
- 100分索取JAVA API文档中文版本,谢谢!
- 子窗口为什么显示父窗口的内容
- weblogic项目部署错误
- Hibernate问题
- xsl的格式怎么弄都不对555555555555555
第二.你在什么地方是否调用了getNation方法
2.并没有调用getNation方法.在此后只是调用describe().