设置POJO(spring 2 + Hibernate JPA)+ MySQL DB的属性时,我刚刚遇到以下异常错误:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190) at com.confloorapp.domain.Floor_$$_javassist_0.setNumberOfEvents(Floor_$$_javassist_0.java) at com.ifloor.services.endpoint.UpdateFloorEventServlet.doGet(UpdateFloorEventServlet.java:59) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at ...
这是一套:
floor.setNumberOfEvents ((Long)numOfEvents);
那是POJO:
@Entity @Table(name="T_FLOOR") public class Floor {
@Id
@Column(name = "FLOOR_ID", unique = true, nullable = false)
private Integer id;
@Column(name = "FLOOR_KEY")
private String floorKey;
@Column(name = "NUMBER_OF_EVENTS")
private Long numberOfEvents;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Long getNumberOfEvents() {
return numberOfEvents;
}
public void setNumberOfEvents(Long numberOfEvents) {
this.numberOfEvents = numberOfEvents;
}
public String getFloorKey() {
return floorKey;
}
public void setFloorKey(String floorKey) {
this.floorKey = floorKey;
}
}
这是MYSQL表定义:
mySQL的
CREATE TABLE `T_FLOOR` (
`FLOOR_ID` int(11) NOT NULL AUTO_INCREMENT,
`FLOOR_KEY` varchar(45) DEFAULT NULL,
`FLOOR_DESC` varchar(45) DEFAULT NULL,
`LOCATION_ID` int(11) DEFAULT NULL,
`NUMBER_OF_EVENTS` bigint(20) DEFAULT NULL,
`LAST_EVENT` timestamp NULL DEFAULT NULL,
`LAST_UPDATE` timestamp NULL DEFAULT NULL,
`LATITUDE` float DEFAULT NULL,
`LONGITUDE` float DEFAULT NULL,
PRIMARY KEY (`FLOOR_ID`),
UNIQUE KEY `FLOOR_ID_UNIQUE` (`FLOOR_ID`),
KEY `FK_floor_location` (`LOCATION_ID`),
CONSTRAINT `FK_door_location` FOREIGN KEY (`LOCATION_ID`) REFERENCES `T_LOCATION` (`LOCATION_ID`)