These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Problem with mapped class. is this a bug
PostPosted: Sun Oct 19, 2003 6:11 pm 
Newbie

Joined: Sun Oct 12, 2003 9:53 pm
Posts: 13
Location: Buenos Aires, Argentina
Hi all I'm having a problem with a mapped class
The exceptions is this

Code:
java.lang.NullPointerException
   at net.sf.jagzilla.hibernate.BugActivityMetaClass15.setPropertyValues(<generated>)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.find(Loader.java:620)
   at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
   at net.sf.jagzilla.hibernate.BugActivityTest.testList(BugActivityTest.java:48)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:395)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)
rethrown as net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of net.sf.jagzilla.hibernate.BugActivity.?
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:167)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.find(Loader.java:620)
   at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
   at net.sf.jagzilla.hibernate.BugActivityTest.testList(BugActivityTest.java:48)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:395)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)
Caused by: java.lang.NullPointerException
   at net.sf.jagzilla.hibernate.BugActivityMetaClass15.setPropertyValues(<generated>)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)
   ... 23 more


I'm using xdoclet, I'm wondering if this is a user error or an hibernate error. I'm sorry I cannot distinguish from stack trace, but NPE... I'd fill a bug report if it's an hibernate problem, and if it's not I'll post more data here If this is not enogh for pointers on how to fix.
Thanks in advance.

PS: this community is awesome![/b][/code]


Top
 Profile  
 
 Post subject: more info
PostPosted: Mon Oct 20, 2003 11:39 am 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
What version of Hibernate are you using? Please post your XML mapping files too.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2003 4:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
In your stack trace, it is written
exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info


Do it, set hibernate.cglib.use_reflection_optimizer=false in your hibernate.cfg.xml file.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Full stack trace
PostPosted: Mon Oct 20, 2003 7:16 pm 
Newbie

Joined: Sun Oct 12, 2003 9:53 pm
Posts: 13
Location: Buenos Aires, Argentina
Code:
Hibernate: select bugactiv0_.bug_id as bug_id, bugactiv0_.bug_when as bug_when, bugactiv0_.fieldId as fieldId, bugactiv0_.who as who, bugactiv0_.added as added, bugactiv0_.attach_id as attach_id, bugactiv0_.removed as removed from bugs_activity bugactiv0_
java.lang.NullPointerException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:170)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.find(Loader.java:620)
   at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
   at net.sf.jagzilla.hibernate.BugActivityTest.testList(BugActivityTest.java:48)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:395)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)
rethrown as net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of net.sf.jagzilla.hibernate.BugActivity.attachId
   at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:49)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:170)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.find(Loader.java:620)
   at net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
   at net.sf.jagzilla.hibernate.BugActivityTest.testList(BugActivityTest.java:48)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:395)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)
Caused by: java.lang.NullPointerException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45)
   ... 24 more


The ouput of the query in db is:
Code:
select bugactiv0_.bug_id as bug_id, bugactiv0_.bug_when as bug_when, bugactiv0_.fieldId as fieldId, bugactiv0_.who as who, bugactiv0_.added as added, bugactiv0_.attach_id as attach_id, bugactiv0_.removed as removed from bugs_activity bugactiv0_


The mapping file:
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="net.sf.jagzilla.hibernate.BugActivity"
        table="bugs_activity"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <composite-id
            name="id"
            class="net.sf.jagzilla.hibernate.BugActivityPrimaryKey"
        >
                     <key-property
                        name="bugId"
                        type="int"
                        column="bug_id"
                />

                     <key-property
                        name="bugWhen"
                        type="java.util.Date"
                        column="bug_when"
                />

                     <key-property
                        name="fieldId"
                        type="int"
                        column="fieldId"
                />

                     <key-property
                        name="who"
                        type="int"
                        column="who"
                />

        </composite-id>

        <property
            name="added"
            type="java.lang.String"
            update="true"
            insert="true"
            column="added"
        />

        <property
            name="attachId"
            type="int"
            update="true"
            insert="true"
            column="attach_id"
        />

        <property
            name="removed"
            type="java.lang.String"
            update="true"
            insert="true"
            column="removed"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-BugActivity.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>



The java classes file
Code:
/*
* Created on Sep 30, 2003
*
*/
package net.sf.jagzilla.hibernate;

import java.io.Serializable;


/**
* represents a record in the table bugs_activity.
*
*
* @author mgriffa
*
* @hibernate.class
*    table="bugs_activity"
*
*/
public class BugActivity implements Serializable{
    private BugActivityPrimaryKey id;
    private int attachId;
    private String added;
    private String removed;

    /**
     * @hibernate.property
     *
     * @return Returns the added.
     */
    public String getAdded() {
        return added;
    }

    /**
     *
     * @param added The added to set.
     */
    public void setAdded(String added) {
        this.added = added;
    }

    /**
     * @hibernate.property column="attach_id"
     *
     * @return Returns the attachId.
     */
    public int getAttachId() {
        return attachId;
    }

    /**
     * @param attachId The attachId to set.
     */
    public void setAttachId(int attachId) {
        this.attachId = attachId;
    }

    /**
     * @hibernate.property
     *
     * @return Returns the removed.
     */
    public String getRemoved() {
        return removed;
    }

    /**
     * @param removed The removed to set.
     */
    public void setRemoved(String removed) {
        this.removed = removed;
    }

    public String toString() {
        return "[BugActivity: " +
                "id="+id+
                "attachId, ="+attachId+
                "attachId, ="+attachId+
                "added, ="+added+
                "removed, ="+removed+
                        " ]";

    }


    /**
     * @hibernate.id generator-class = "BugActivityPrimaryKey"
     *
     * @return Returns the id.
     */
    public BugActivityPrimaryKey getId() {
        return id;
    }

    /**
     * @param id The id to set.
     */
    public void setId(BugActivityPrimaryKey id) {
        this.id = id;
    }

}

/*
* Created on Sep 30, 2003
*
*/
package net.sf.jagzilla.hibernate;

import java.io.Serializable;
import java.util.Date;

/**
* represents the primary key for the class BugActivity.
*
* @see BugActivity
*
* @author mgriffa
*
*
*/
public class BugActivityPrimaryKey implements Serializable{
    private int bugId;
    private int who;
    private Date bugWhen;
    private int fieldId;
   
    /**
     * @hibernate.property column="bug_id"
     *
     * @return Returns the bugId.
     */
    public int getBugId() {
        return bugId;
    }

    /**
     * @param bugId The bugId to set.
     */
    public void setBugId(int bugId) {
        this.bugId = bugId;
    }

    /**
     * @hibernate.property column="bug_when"
     *
     * @return Returns the bugWhen.
     */
    public Date getBugWhen() {
        return bugWhen;
    }

    /**
     * @param bugWhen The bugWhen to set.
     */
    public void setBugWhen(Date bugWhen) {
        this.bugWhen = bugWhen;
    }

    /**
     * @hibernate.property
     *
     * @return Returns the fieldId.
     */
    public int getFieldId() {
        return fieldId;
    }

    /**
     * @param fieldId The fieldId to set.
     */
    public void setFieldId(int fieldId) {
        this.fieldId = fieldId;
    }

    /**
     * @hibernate.property
     *
     * @return Returns the who.
     */
    public int getWho() {
        return who;
    }

    /**
     * @param who The who to set.
     */
    public void setWho(int who) {
        this.who = who;
    }

    public String toString() {
        return "[BugActivityPrimaryKey: " +
                "bugId="+bugId+
                "who, ="+who+
                "bugWhen, ="+bugWhen+
                "fieldId, ="+fieldId+
                        " ]";

    }
    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        // TODO Auto-generated method stub
        return super.equals(obj);
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        // TODO Auto-generated method stub
        return super.hashCode();
    }

}



Is there more info I should post?[/b]


Top
 Profile  
 
 Post subject: Output of the query
PostPosted: Mon Oct 20, 2003 7:18 pm 
Newbie

Joined: Sun Oct 12, 2003 9:53 pm
Posts: 13
Location: Buenos Aires, Argentina
Code:
mysql> select bugactiv0_.bug_id as bug_id, bugactiv0_.bug_when as bug_when, bugactiv0_.fieldId as fieldId, bugactiv0_.who as who, bugactiv0_.added as added, bugactiv0_.attach_id as attach_id, bugactiv0_.removed as removed from bugs_activity bugactiv0_;
+--------+---------------------+---------+-----+----------+-----------+---------+
| bug_id | bug_when            | fieldId | who | added    | attach_id | removed |
+--------+---------------------+---------+-----+----------+-----------+---------+
|     17 | 2003-10-14 19:59:02 |       8 |   1 | ASSIGNED |      NULL | NEW     |
+--------+---------------------+---------+-----+----------+-----------+---------+
1 row in set (0.01 sec)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2003 10:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I think this says it pretty succintly
Quote:
rethrown as net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of net.sf.jagzilla.hibernate.BugActivity.attachId


BugActivity's attachId property is of primitive type int. In java, you cannot assign null values to variables of primitive type.


Top
 Profile  
 
 Post subject: Solution?
PostPosted: Tue Oct 21, 2003 3:23 pm 
Newbie

Joined: Sun Oct 12, 2003 9:53 pm
Posts: 13
Location: Buenos Aires, Argentina
I see now the problem is clear:
Code:
rethrown as net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of net.sf.jagzilla.hibernate.BugActivity.attachId


Do I have to set this attribute as Integer, or is there any mapping option that would skip primitive assignement when null?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Integer

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.