2011-03-21 5 views
1

以下のコードを参照してください。 DeviceDAO、Device、およびMobileuserは、休止状態で生成されたオブジェクトです。このプロセスは、私がmobileUser.getPin()を呼び出す2番目のif条件に到達するまで機能します。問題は、mobileUserのプロパティ(ピンなど)がnullであることです。値はDBに存在しますが、それらはヌルなので、私の呼び出しはnullポインタの例外をスローします。 Mobileuserのプロパティは、休止状態によって水和されていません。どんな助けもありがとうございます。ありがとう。水和していない冬眠関連オブジェクト

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のHibernateのリバースエンジニアリングを使用しています。アノテーションをマッピングに使用する。ここで

はMobileuser.java

 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; 
    } 

} 

であり、これは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; 
    } 

} 
+0

「Mobileuser」のマッピングを表示してください。 –

答えて

0

これが起こると私は恐れますが、私はちょうど昼食から戻ってきましたが、今は正しく動作しています。以前から変更を加えていませんでしたが、今はうれしいです。何が原因かわからない

デバッグヘルプありがとう@Corey。

2

Mobileuser.hbmがあなたのMobileuserクラスはメソッドgetPinを(持っていながら、 "piin" という名前のプロパティを持っています) 。これらのうちの1つがタイプミスである可能性はありますか?彼らは同じ情報を表すことを意図していると仮定して一致する必要があります。 setter、setPin(String)またはsetPiin(String)のいずれかである必要があります。

dbに列「piin」がある場合は、プロパティピンを列piinにマップするようにマッピングを変更することはできますが、将来はdbからのマッピングを再生成できません。

+0

実際はマッピングは正しいです。最初は、このメッセージのコードを混同しないようにPINを変更しました(逆火と推測します)。私の実際のコードでは、マッピングとgetter/setterの名前はcorerct(piin、getPiin、setPiin)です。ありがとう。 – kmehta

+0

あなたのマッピングとファイルの両方がpiinを使用していますが、あなたはまだ問題が言及されています... Mobileuser.javaのコードを質問に追加できますか? – Corey

+0

Mobileuser.javaは、永続プロパティごとにgetterおよびsetterを持つ非常にシンプルな直列化可能なPOJOオブジェクトです。 – kmehta

関連する問題