这些标注尽量都要写到get方法的头上,我无意中把下面的标注写到了定义变量的头上时候,发生了错误。
报告错误:java.lang.NullPointerException
怎么回事,刚刚我试了下把@Id放到getId()方法的头上结果也报上面那样的错误,然后我再把@Id又放回到private Integer id;的头上结果就没错了。这个问题要待解决下...(我个人认为都放到get的头上,但是id要放到定义的头上,这个我也不知道是什么原因)
private Set<SiteChannel> siteChannelCollection = new HashSet<SiteChannel>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "site")
public Set<SiteChannel> getSiteChannelCollection() {
return siteChannelCollection;
}
public void setSiteChannelCollection(Set<SiteChannel> siteChannelCollection) {
this.siteChannelCollection = siteChannelCollection;
}
private Site site;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "site_id")
public Site getSite() {
return site;
}
public void setSite(Site site) {
this.site = site;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created", length = 19)
public Date getCreated() {
return this.created;
}
public void setCreated(Date created) {
this.created = created;
}
参考的例子Site.java
package cn.ctit.cms.entity;
// Generated Feb 3, 2009 4:08:09 AM by Hibernate Tools 3.2.2.GA
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Transient;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Parent;
import org.hibernate.validator.Length;
import org.hibernate.validator.Min;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
import cn.ctit.cms.entity.pay.Biller;
import cn.ctit.cms.entity.pay.Joinoption;
/**
* Site generated by hbm2java
*/
@Entity
@Table(name = "site", catalog = "cms")
public class Site implements java.io.Serializable {
private Long id;
private String name;
private String description;
private String siteUrl;
private Short siteType;
private String ioUrl;
private String ioService;
private Integer ioPort;
private String ioUser;
private String ioPass;
private String defaultFormat;
private Boolean enable = true;
private Short status;
private Date created;
private Date modified;
private Long serverId;
private String template;
private Set<SiteChannel> siteChannels = new HashSet<SiteChannel>(0);
private Set<SiteSchedule> siteSchedules = new HashSet<SiteSchedule>(0);
private Set<Joinoption> joinoptions = new HashSet<Joinoption>(0);
private Set<Biller> billers = new HashSet<Biller>(0);
//NATS
private String nats_siteid;
public Site() {
}
public Site(String name, String description, String siteUrl,
Short siteType, String ioUrl, String ioService, Integer ioPort,
String ioUser, String ioPass, String defaultFormat, Boolean enable,
Short status, Date created, Date modified,
Set<SiteChannel> siteChannels, Set<SiteSchedule> siteSchedules,Long serverId) {
this.name = name;
this.description = description;
this.siteUrl = siteUrl;
this.siteType = siteType;
this.ioUrl = ioUrl;
this.ioService = ioService;
this.ioPort = ioPort;
this.ioUser = ioUser;
this.ioPass = ioPass;
this.defaultFormat = defaultFormat;
this.enable = enable;
this.status = status;
this.created = created;
this.modified = modified;
this.siteChannels = siteChannels;
this.siteSchedules = siteSchedules;
this.serverId = serverId;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@NotNull
@Column(name = "name", length = 100)
@Length(max = 100)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "description", length = 200)
@Length(max = 200)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@NotNull
@Column(name = "site_url", length = 200)
@Length(max = 200)
public String getSiteUrl() {
return this.siteUrl;
}
public void setSiteUrl(String siteUrl) {
this.siteUrl = siteUrl;
}
@Column(name = "site_type")
public Short getSiteType() {
return this.siteType;
}
public void setSiteType(Short siteType) {
this.siteType = siteType;
}
@NotNull
@Column(name = "io_url", length = 200)
@Length(max = 200)
public String getIoUrl() {
return this.ioUrl;
}
public void setIoUrl(String ioUrl) {
this.ioUrl = ioUrl;
}
@Pattern(regex="[a-zA-Z]+[0-9]*",message="Please enter right value : transform!")
@Column(name = "io_service", length = 50)
@Length(max = 50)
public String getIoService() {
return this.ioService;
}
public void setIoService(String ioService) {
this.ioService = ioService;
}
@Min(value=1)
@Column(name = "io_port")
public Integer getIoPort() {
return this.ioPort;
}
public void setIoPort(Integer ioPort) {
this.ioPort = ioPort;
}
@NotNull
@Column(name = "io_user", length = 50)
@Length(max = 50)
public String getIoUser() {
return this.ioUser;
}
public void setIoUser(String ioUser) {
this.ioUser = ioUser;
}
@NotNull
@Column(name = "io_pass", length = 50)
@Length(max = 50)
public String getIoPass() {
return this.ioPass;
}
public void setIoPass(String ioPass) {
this.ioPass = ioPass;
}
@Column(name = "default_format", length = 200)
@Length(max = 200)
public String getDefaultFormat() {
return this.defaultFormat;
}
public void setDefaultFormat(String defaultFormat) {
this.defaultFormat = defaultFormat;
}
@Column(name = "enable")
public Boolean getEnable() {
return this.enable;
}
public void setEnable(Boolean enable) {
this.enable = enable;
}
@Column(name = "status")
public Short getStatus() {
return this.status;
}
public void setStatus(Short status) {
this.status = status;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created", length = 19)
public Date getCreated() {
return this.created;
}
public void setCreated(Date created) {
this.created = created;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modified", length = 19)
public Date getModified() {
return this.modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "site")
public Set<SiteChannel> getSiteChannels() {
return this.siteChannels;
}
public void setSiteChannels(Set<SiteChannel> siteChannels) {
this.siteChannels = siteChannels;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "site")
public Set<SiteSchedule> getSiteSchedules() {
return this.siteSchedules;
}
public void setSiteSchedules(Set<SiteSchedule> siteSchedules) {
this.siteSchedules = siteSchedules;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "site")
public Set<Joinoption> getJoinoptions() {
return joinoptions;
}
public void setJoinoptions(Set<Joinoption> joinoptions) {
this.joinoptions = joinoptions;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "site")
public Set<Biller> getBillers() {
return billers;
}
public void setBillers(Set<Biller> billers) {
this.billers = billers;
}
@Column(name = "server_id")
public Long getServerId() {
return this.serverId;
}
public void setServerId(Long serverId) {
this.serverId = serverId;
}
@Column(name = "nats_siteid")
public String getNats_siteid() {
return nats_siteid;
}
public void setNats_siteid(String nats_siteid) {
this.nats_siteid = nats_siteid;
}
//@Transient
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
}
分享到:
相关推荐
这是JPA标签配置手册,从ORACLE官方得到的资料,里面对JPA所有的标签都进行详细的说明。 Index of Annotations • A o @AssociationOverride o @AssociationOverrides o @AttributeOverride o @AttributeOverrides ...
相关文章: JPA标注 EJB的资料辅导(7) EJB的资料辅导(6) 推荐圈子: Database圈子 更多相关推荐 1.@Entity
jpa的标注文档,中文,heml格式,官方文档,解压后一个html页,一个文件夹。
作为 Java 企业版 5 (Java EE 5) Enterprise Java Bean (EJB) 3.0 规范的组成部分,Java 持续性 API (JPA) 显著简化了 EJB 持续性并提供了一个对象关系映射方法,该方法使您可以采用声明方式定义如何通过一种标准的...
jpa 基础 常用 标注 注解,一些常用注解 的说明,更好的jpa入门。
作为 Java 企业版 5 (Java EE 5) Enterprise Java Bean (EJB) 3.0 规范的组成部分,Java 持续性 API (JPA) 显著 简化了 EJB 持续性并提供了一个对象关系映射方法,该方法使您可以采用声明方式定义如何通过一种...
JPA教程JPA教程JPA教程JPA教程JPA教程
jpa jpa规范 jpa源码 jpa jpa规范 jpa源码
jpajpajpajpajpajpajpajpajpajpajpajpajpa
包括TOPLink JPA,Hibernate JPA,Open Jpa,jpa批注
JPA
JPA视频_PPT及源码 · 1. JPA视频_概述 · 2. JPA视频_HelloWorld · 3. JPA视频_基本注解 · 4. JPA视频_Transient注解 · 5. JPA视频_Temporal注解 · 6. JPA视频_Table主键生成策略 · 7. JPA视频_...
jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联映射jpa 关联...
JPA注解详解 hibernate 标注 适合各种数据库 Hibernate+JPA注解教程
Spring Data JPA 简化 JPA 开发
JPA学习参考文档 JPA学习参考文档 JPA学习参考文档
Spring Data JPA API。 Spring Data JPA 开发文档。 官网 Spring Data JPA API。
JPA JAPJPA JAPJPA JAPJPA JAPJPA JAPJPA JAPJPA JAPJPA JAPJPA JAPJPA JAP
JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询JPA分页查询与条件分页查询...
jpa 全面学习资料 入门 实战 示例 jpa开发手册 JPA_全面讲解 JPA使用入门_基础 JPA学习笔记 JPA注解 JPA简介