2011-03-21 8 views
1

아래 코드를 참조하십시오. DeviceDAO, Device 및 Mobileuser는 최대 절전 모드로 생성 된 개체입니다. 이 프로세스는 내가 mobileUser.getPin()을 호출하는 두 번째 "if"조건에 도달 할 때까지 작동합니다. 문제는 모바일 사용자의 속성 (예 : 핀)이 null이라는 것입니다. 값은 DB에 있지만 null 영역이므로 내 호출은 null 포인터 예외를 발생시킵니다. 모바일 사용자의 속성은 최대 절전 모드로 수분을 공급받지 못했습니다. 어떤 도움을 주셔서 감사합니다. 감사. 요청에 따라최대 절전 모드 관련 객체가 수화되지 않음

DeviceDAO deviceDao = new DeviceDAO(); 
    List<Device> devices = deviceDao.findByUdid(requestTokenModel.getUdid()); 

       if(!devices.isEmpty()) 
      { 
       Device device = devices.get(0); 
       Mobileuser mobileUser =device.getMobileuser(); 
       if(mobileUser.getPin().contentEquals(requestTokenModel.getPiin()) && mobileUser.getIsactive() == "Y") 
         { 
          //omitted      
         } 
      } 

UPDATE

는 여기에 몇 가지 추가 정보입니다 : 내가 생성 된 데이터 객체와 DAO 객체은 MyEclipse 최대 절전 모드 리버스 엔지니어링을 사용하고

. 주석을 사용하여 매핑하기. 여기

 package com.myeclipse.hibernate; 

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.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import org.hibernate.annotations.GenericGenerator; 

/** 
* Mobileuser entity. @author MyEclipse Persistence Tools 
*/ 
@Entity 
@Table(name = "MOBILEUSER", schema = "WARPVALID") 
public class Mobileuser implements java.io.Serializable { 

    // Fields 

    private Integer mobileuserid; 
    private Servicetype servicetype; 
    private String lastname; 
    private String username; 
    private String firstname; 
    private String organization; 
    private String piin; 
    private String isactive; 
    private Date createdate; 
    private Date modifydate; 
    private String email; 
    private String isaccepted; 
    private Set<Registration> registrations = new HashSet<Registration>(0); 
    private Set<Device> devices = new HashSet<Device>(0); 

    // Constructors 

    /** default constructor */ 
    public Mobileuser() { 
    } 

    /** minimal constructor */ 
    public Mobileuser(String lastname, String username, String firstname, 
      String piin, String isactive, Date createdate, Date modifydate, 
      String isaccepted) { 
     this.lastname = lastname; 
     this.username = username; 
     this.firstname = firstname; 
     this.piin = piin; 
     this.isactive = isactive; 
     this.createdate = createdate; 
     this.modifydate = modifydate; 
     this.isaccepted = isaccepted; 
    } 

    /** full constructor */ 
    public Mobileuser(Servicetype servicetype, String lastname, 
      String username, String firstname, String organization, 
      String piin, String isactive, Date createdate, Date modifydate, 
      String email, String isaccepted, Set<Registration> registrations, 
      Set<Device> devices) { 
     this.servicetype = servicetype; 
     this.lastname = lastname; 
     this.username = username; 
     this.firstname = firstname; 
     this.organization = organization; 
     this.piin = piin; 
     this.isactive = isactive; 
     this.createdate = createdate; 
     this.modifydate = modifydate; 
     this.email = email; 
     this.isaccepted = isaccepted; 
     this.registrations = registrations; 
     this.devices = devices; 
    } 

    // Property accessors 
    @GenericGenerator(name = "generator", strategy = "increment") 
    @Id 
    @GeneratedValue(generator = "generator") 
    @Column(name = "MOBILEUSERID", unique = true, nullable = false, precision = 9, scale = 0) 
    public Integer getMobileuserid() { 
     return this.mobileuserid; 
    } 

    public void setMobileuserid(Integer mobileuserid) { 
     this.mobileuserid = mobileuserid; 
    } 

    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name = "SERVICETYPEID") 
    public Servicetype getServicetype() { 
     return this.servicetype; 
    } 

    public void setServicetype(Servicetype servicetype) { 
     this.servicetype = servicetype; 
    } 

    @Column(name = "LASTNAME", nullable = false, length = 30) 
    public String getLastname() { 
     return this.lastname; 
    } 

    public void setLastname(String lastname) { 
     this.lastname = lastname; 
    } 

    @Column(name = "USERNAME", nullable = false, length = 20) 
    public String getUsername() { 
     return this.username; 
    } 

    public void setUsername(String username) { 
     this.username = username; 
    } 

    @Column(name = "FIRSTNAME", nullable = false, length = 30) 
    public String getFirstname() { 
     return this.firstname; 
    } 

    public void setFirstname(String firstname) { 
     this.firstname = firstname; 
    } 

    @Column(name = "ORGANIZATION", length = 50) 
    public String getOrganization() { 
     return this.organization; 
    } 

    public void setOrganization(String organization) { 
     this.organization = organization; 
    } 

    @Column(name = "PIIN", nullable = false, length = 10) 
    public String getPiin() { 
     return this.piin; 
    } 

    public void setPiin(String piin) { 
     this.piin = piin; 
    } 

    @Column(name = "ISACTIVE", nullable = false, length = 1) 
    public String getIsactive() { 
     return this.isactive; 
    } 

    public void setIsactive(String isactive) { 
     this.isactive = isactive; 
    } 

    @Temporal(TemporalType.DATE) 
    @Column(name = "CREATEDATE", nullable = false, length = 7) 
    public Date getCreatedate() { 
     return this.createdate; 
    } 

    public void setCreatedate(Date createdate) { 
     this.createdate = createdate; 
    } 

    @Temporal(TemporalType.DATE) 
    @Column(name = "MODIFYDATE", nullable = false, length = 7) 
    public Date getModifydate() { 
     return this.modifydate; 
    } 

    public void setModifydate(Date modifydate) { 
     this.modifydate = modifydate; 
    } 

    @Column(name = "EMAIL", length = 50) 
    public String getEmail() { 
     return this.email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 

    @Column(name = "ISACCEPTED", nullable = false, length = 1) 
    public String getIsaccepted() { 
     return this.isaccepted; 
    } 

    public void setIsaccepted(String isaccepted) { 
     this.isaccepted = isaccepted; 
    } 

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "mobileuser") 
    public Set<Registration> getRegistrations() { 
     return this.registrations; 
    } 

    public void setRegistrations(Set<Registration> registrations) { 
     this.registrations = registrations; 
    } 

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "mobileuser") 
    public Set<Device> getDevices() { 
     return this.devices; 
    } 

    public void setDevices(Set<Device> devices) { 
     this.devices = devices; 
    } 

} 

Mobileuser.java

입니다 그리고 이것은 Device.java입니다 :

package com.myeclipse.hibernate; 

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.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 
import org.hibernate.annotations.GenericGenerator; 

/** 
* Device entity. @author MyEclipse Persistence Tools 
*/ 
@Entity 
@Table(name = "DEVICE", schema = "WARPVALID") 
public class Device implements java.io.Serializable { 

    // Fields 

    private Integer deviceid; 
    private Mobileuser mobileuser; 
    private String udid; 
    private String applicationversion; 
    private String dataversion; 
    private Set<Authentication> authentications = new HashSet<Authentication>(0); 

    // Constructors 

    /** default constructor */ 
    public Device() { 
    } 

    /** minimal constructor */ 
    public Device(Mobileuser mobileuser, String udid) { 
     this.mobileuser = mobileuser; 
     this.udid = udid; 
    } 

    /** full constructor */ 
    public Device(Mobileuser mobileuser, String udid, 
      String applicationversion, String dataversion, 
      Set<Authentication> authentications) { 
     this.mobileuser = mobileuser; 
     this.udid = udid; 
     this.applicationversion = applicationversion; 
     this.dataversion = dataversion; 
     this.authentications = authentications; 
    } 

    // Property accessors 
    @GenericGenerator(name = "generator", strategy = "increment") 
    @Id 
    @GeneratedValue(generator = "generator") 
    @Column(name = "DEVICEID", unique = true, nullable = false, precision = 9, scale = 0) 
    public Integer getDeviceid() { 
     return this.deviceid; 
    } 

    public void setDeviceid(Integer deviceid) { 
     this.deviceid = deviceid; 
    } 

    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name = "MOBILEUSERID", nullable = false) 
    public Mobileuser getMobileuser() { 
     return this.mobileuser; 
    } 

    public void setMobileuser(Mobileuser mobileuser) { 
     this.mobileuser = mobileuser; 
    } 

    @Column(name = "UDID", nullable = false, length = 20) 
    public String getUdid() { 
     return this.udid; 
    } 

    public void setUdid(String udid) { 
     this.udid = udid; 
    } 

    @Column(name = "APPLICATIONVERSION", length = 20) 
    public String getApplicationversion() { 
     return this.applicationversion; 
    } 

    public void setApplicationversion(String applicationversion) { 
     this.applicationversion = applicationversion; 
    } 

    @Column(name = "DATAVERSION", length = 20) 
    public String getDataversion() { 
     return this.dataversion; 
    } 

    public void setDataversion(String dataversion) { 
     this.dataversion = dataversion; 
    } 

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "device") 
    public Set<Authentication> getAuthentications() { 
     return this.authentications; 
    } 

    public void setAuthentications(Set<Authentication> authentications) { 
     this.authentications = authentications; 
    } 

} 
당신의 Mobileuser 클래스는 방법 getPin있는 동안
+0

'Mobileuser'에 대한 매핑을 보여주십시오. –

답변

0

내가 이런 일이 생기면 두려워하지만 점심 식사에서 돌아 왔고 이제는 제대로 작동합니다. 이전에는 변경하지 않았지만 지금은 만족합니다. 무슨 일이 일어나고 있는지 전혀 몰랐습니다.

감사합니다. 디버깅 도움말 @Corey.

2

Mobileuser.hbm은) ("접합 piin"라는 이름의 속성이 있습니다 . 이 중 하나가 오타 일 수 있습니까? 그들은 동일한 정보를 나타 내기위한 것이라는 가정하에 일치해야합니다. setter, setPin (String) 또는 setPiin (String) 중 어느 것이어야한다.

db에 "piin"열이있는 경우 나중에 db에서 매핑을 재생성 할 수 없지만 속성 핀을 piin 열에 매핑하도록 매핑을 변경할 수 있습니다.

+0

실제로 매핑이 정확합니다. 처음에는이 메시지에서 코드를 변경하여 PIN을 혼란스럽지 않게 보였습니다 (역풍으로 추정). 실제 코드에서 매핑 및 getter/setter 이름은 corerct (piin, getPiin, setPiin)입니다. 감사. – kmehta

+0

그래서 맵핑과 파일 둘 다 파이썬을 사용하며 여전히 문제가 언급되고 있습니다 ... Mobileuser.java에 대한 코드를 질문에 추가 할 수 있습니까? – Corey

+0

Mobileuser.java는 매우 간단한 직렬화 가능 POJO 객체이며 각 영구 속성에 대한 getter 및 setters가 있습니다. – kmehta