February 2012 Posts

My Wedding Day

February 11th 2012 is my Wedding day

Here are some picture from my Wedding.

Btw please guess, which one is me :D

(L)

Google+

Welcome Home, My New Fossil

My wrist watches, Kenneth Cole ( left ), Fossil ( center ) and my latest Fossil ( right ).
Welcome home dear (L) .

Google+

NullPointerException When Using JPA

I got this weird error while trying to select a data using Eclipselink JPA on my Glassfish AppServer

[#|2012-02-02T00:47:09.746+0700|SEVERE| glassfish3.0.1|javax.enterprise.system.std.com.sun. enterprise.v3. services.impl|_ThreadID=31;_ThreadName=http-thread-pool-8080-(1);| java.lang.NullPointerException
	at com.edw.xxx.dto.Account._persistence_set(Account.java)

here is the complete details of my error

[#|2012-02-02T00:47:09.746+0700|SEVERE|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3. services.impl|_ThreadID=31;_ThreadName=http-thread-pool-8080-(1);| java.lang.NullPointerException
	at com.edw.xxx.dto.Account._persistence_set(Account.java)
	at org.eclipse.persistence.internal.descriptors.PersistenceObjectAttributeAccessor. setAttributeValueInObject(PersistenceObjectAttributeAccessor.java:46)
	at org.eclipse.persistence.mappings.DatabaseMapping. setAttributeValueInObject(DatabaseMapping.java:1367)
	at org.eclipse.persistence.mappings.DatabaseMapping. readFromRowIntoObject(DatabaseMapping.java:1258)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildAttributesIntoObject(ObjectBuilder.java:331)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:660)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildWorkingCopyCloneNormally(ObjectBuilder.java:582)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObjectInUnitOfWork(ObjectBuilder.java:551)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:491)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:443)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery. buildObject(ObjectLevelReadQuery.java:635)
	at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:838)
	at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:464)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:997)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1021)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:453)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:714)

And here is the code for my Account.java

@Entity
@Table(name = "account")
@XmlRootElement
@NamedQueries({ 
    @NamedQuery(name = "Account.findAll", query = "SELECT a FROM Account a")
    })
public class Account implements Serializable {
    
    private static final long serialVersionUID = 1L;
	
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "acc_no")
    private Long accNo;
	
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
	
    @Basic(optional = false)
    @Column(name = "pwd")
    private String pwd;
	
    @Basic(optional = false)
    @Column(name = "gender")
    private char gender;	

    public Account() {
    }

    // other setters and getters   
}

Actually, the main suspect here is the attribute “gender”. It shows NullPointerException due to “gender” is a basic type ( char ) while the row “gender” in database is null.

(&) Weird isnt it?

Google+