-->
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.  [ 12 posts ] 
Author Message
 Post subject: unidirectional Set:PropertyAccessException: field value
PostPosted: Wed Jan 11, 2006 11:56 am 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
Hallo there :)
I have a 'Data' Object that can have many Comments (0...n). The 'Comment'-Object doesnt have to know to what 'Data' it is refering to. (unidirectional relationship). Implemented is a Hashset in the 'Data' Object to store the 'Comment'.
What is wrong with:
<set name="comments" cascade="all">
<key column="COMMENTS_" />
<one-to-many class="de.bla.Comment" />
</set>

Thank you in advance for helping me :)

Hibernate version:
Hibernate 3.1 rc3
Name and version of the database you are using:
mysql 5
Mapping documents:
de.bla.Data.hbm.xml
Code:
<hibernate-mapping default-access="field">

   <class name="de.bla.Data" table="ADET_ID_DATA"
      discriminator-value="D">
      <id name="id" column="ID_">
         <generator class="native" />
      </id>
      <discriminator type="char" column="CLASS_" />

      <property name="name" column="NAME_" />

      <property name="initialDate" column="INITDATE_"
         type="java.util.Date" />

      <property name="requestedDate" column="REQDATE_"
         type="java.util.Date" />

      <many-to-one name="omResponsible"
         class="de.bla.User" column="OMRESP_"
         foreign-key="FK_ADET_OMRESP" />

      <many-to-one name="requestor" class="de.bla.User"
         column="REQUESTOR_" foreign-key="FK_ADET_REQUESTOR" />

      <many-to-one name="version" class="de.bla.Version"
         column="VERSION_" foreign-key="FK_ADET_VERSION" />

      <set name="comments" cascade="all">
         <key column="COMMENTS_" />
         <one-to-many class="de.bla.Comment" />
      </set>
   </class>

</hibernate-mapping>

de.bla.Comment.hbm.xml
Code:
<hibernate-mapping default-access="field">

   <class name="de.bla.Comment" table="ADET_ID_COMMENT"
      discriminator-value="C">
      <id name="id" column="ID_">
         <generator class="native" />
      </id>
      <discriminator type="char" column="CLASS_" />
      <property name="name" column="NAME_" />
      <property name="content" column="CONTENT_" />
      <property name="creationDate" column="DATE_" />
      <many-to-one name="creator" class="de.bla.User"
         column="CREATOR_" cascade="all" foreign-key="FK_ADET_USER" />

   </class>

</hibernate-mapping>


Code
Code:
   public void addComment(String crName, String commentText,
         String requestorName) {
      Comment comment = new Comment();
      comment.setContent(commentText);
      comment.setCreationDate(new Date());
      DataSession session = factory.openDataSession();

      User requestor = session.getUserByName(requestorName);
      if (requestor != null)
         comment.setCreator(requestor);
      Data data = session.getDataByName(crName);
      session.beginTransaction();
      data.addComment(comment);
      session.saveData(data);
      session.commitTransactionAndClose();
   }


stack trace:

    Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.bla.data.Comment.id
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
    at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
    at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3256)
    at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2982)
    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
    at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:459)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:84)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:496)
    at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
    at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
    at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:908)
    at de.bla.DataSession.commitTransaction(DataSession.java:51)
    ... 40 more


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 9:48 am 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi!

Hibernate seems to be unable finding the 'id' property in your de.bla.data.Comment class; would be interesting to see the code for that class.

All the best,

René


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2006 4:30 am 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
ReneStolp wrote:
Hi!

Hibernate seems to be unable finding the 'id' property in your de.bla.data.Comment class; would be interesting to see the code for that class.

All the best,

René

But it is existing:

Code:
public class Comment extends Entity implements Serializable {
   private static final long serialVersionUID = 1L;
   protected String content = null;
   protected User creator = null;
   protected Date creationDate = null;
   protected Data referringData = null;
...


The 'id' attribute is inherited from the Entity Object:
Code:
public class Entity implements Serializable {
   private static final long serialVersionUID = 1L;
   long id = 0;
   protected String name = null;
   /* permissions is a set of java.security.Permission's */
   protected Set permissions = null;
...
public long getId() {
      return id;
   }
   
   public void setId(long id) {
      this.id = id;
   }
...


This class is the superclass for other classes, but only 'Comment' didn't work. The Entity Class itself has no hbm-mapping file.
The problem is imho the unidirectional 1-n relationship between 'Data' and 'Comment'. When I am looking directly at the mysql-db, hibernate didn't create any column in the 'Data' Object or any additional mapping table..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2006 5:07 am 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi!

Ok, I see it is there. There are two things that I see, while I do not know, if they are part of the problem:

  1. You are accessing your fields direct, not via getter/setter (by specfying default-access="field").
  2. The field id has no access modifier, making it effectively package private.
I have not tested, if any of this may be the problem, but you can probably easily test it yourself: Try either to modify the access modifier to private or protected and/or change the access type, at least for this field, to getter/setter.

Let me know, if that helped.

All the best,

René


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2006 6:53 am 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
Hmm, that didn't work: whether public oder protected..
It must be the <list> mapping.

Data.hbm.xml

Code:
   <class name="de.bla.Data" table="ADET_ID_DATA"
      discriminator-value="D">
      <id name="id" column="ID_">
         <generator class="native" />
      </id>
      <discriminator type="char" column="CLASS_" />
      ...
      <list name="comments" cascade="all" inverse="true">
        <key column="ID_" />
        <list-index column="COMMENT_INDEX"/>   
        <one-to-many class="de.bla.Comment"/>
      </list>
...


What I dont understand at all:
Code:
mysql> DESCRIBE adet_id_data;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| ID_        | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| CLASS_     | char(1)      | NO   |     |         |                |
| NAME_      | varchar(255) | YES  |     | NULL    |                |
| INITDATE_  | datetime     | YES  |     | NULL    |                |
| REQDATE_   | datetime     | YES  |     | NULL    |                |
| OMRESP_    | bigint(20)   | YES  | MUL | NULL    |                |
| REQUESTOR_ | bigint(20)   | YES  | MUL | NULL    |                |
| VERSION_   | bigint(20)   | YES  | MUL | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
8 rows in set (0.02 sec)

mysql> DESCRIBE adet_id_comment;
+---------------+--------------+------+-----+---------+----------------+
| Field         | Type         | Null | Key | Default | Extra          |
+---------------+--------------+------+-----+---------+----------------+
| ID_           | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| CLASS_        | char(1)      | NO   |     |         |                |
| NAME_         | varchar(255) | YES  |     | NULL    |                |
| CONTENT_      | text         | YES  |     | NULL    |                |
| DATE_         | datetime     | YES  |     | NULL    |                |
| CREATOR_      | bigint(20)   | YES  | MUL | NULL    |                |
| COMMENT_INDEX | int(11)      | YES  |     | NULL    |                |
+---------------+--------------+------+-----+---------+----------------+
7 rows in set (0.02 sec)


I dont understand why there is NO entry in the 'Data' table and there IS A entry in the 'Comment' Table. It should be the other way round, shouldn't it? A 'Data' knows its 'Comments' and thats all.

btw, the current error is when I am trying to add a Comment-Instance to the Data Object (= ArrayList.add( ))
    Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentList
    at org.hibernate.engine.StatefulPersistenceContext.reassociateIfUninitializedProxy(StatefulPersistenceContext.ja
    va:490)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.reassociateIfUninitializedProxy(DefaultSaveOrUpdateE
    ventListener.java:76)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:59)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:496)
    at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
    at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
    at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:908)
    at de.bla.DataSession.commitTransaction(DataSession.java:51)
    at de.bla.DataSession.commitTransactionAndClose(DataSession.java:75)
    at de.bla.DataService.addComment(DataService.java:192)

The Code:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2006 9:05 am 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
I am loosing hope :(
I tried several combinations (1-n, n-n, set/list, lazy, cascade, inverse usw) but in every case one of the two errors occurs (ClassCastException: org.hibernate.collection.PersistentList or PropertyAccessException: could not get a field value).
I think I have also fundamental understanding problems: How to solve the 1-n relationship (data-comment):
a) SQL: in the Data-Table a Column that references to the Comment-Table. This Column is as well as foreign key as primary key.
b) SQL: an extra mapping table with a Data and a Comment Column (both PK and FK)
I am using the 'updata' flag in the cfg-file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 5:17 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
why dont u try overriding the getter/setters in your persistent class and change to access="property"

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 5:42 am 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
Changed access to 'property' and removed the deriving from the Entity class:
Caused by: java.lang.RuntimeException: couldn't commit transaction
at de.bla.data.hibernate.DataSession.commitTransaction(DataSession.java:55)
at de.bladata.hibernate.DataSession.commitTransactionAndClose(DataSession.java:75)
at de.bladata.mbean.DataService.addComment(DataService.java:192)
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:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141) ... 33 more
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of de.bla.data.Comment.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3231)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2965)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:215)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:697)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1192)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
at de.bla.data.hibernate.DataSession.commitTransaction(DataSession.java:51)
... 40 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 6:18 am 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
And derived from Entity:
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of de.bla.data.Entity.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 12:04 pm 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
if everything is fine , it should give u result . plz check for any type mismatches in ur persistent class or mapping files . i've encountered such problems :)

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 12:19 pm 
Newbie

Joined: Mon Nov 28, 2005 12:07 pm
Posts: 17
nothing is fine :(
And there are no typos because I have some other classes that are working in the same way. But this is the only 1-n relation (List-Implementation) - the n-1 relations are ok. Maybe the error is in the persisting code (simplified):
Code:
//retrieving saved 'Data' Object
Data data = session.getDataByName(crName);
//creating new 'Comment' Object
Comment comment = new Comment();
session.beginTransaction();
//adding the comment to the List
data.addComment(comment);
//saving the modified 'Data' Object
session.save(data);
session.commitTransactionAndClose();

I also tested with additional saving the 'Comment' Object:
Code:
session.save(comment);

but no success...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 11:05 pm 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
do u have a no argument constructor in your persistent class ?

as per api docs, you can get a PropertyAccessException due to

* failure of a security check
* an exception occurring inside the getter or setter method
* a nullable database column was mapped to a primitive-type property
* the Hibernate type was not castable to the property type (or vice-versa)


check for any of these

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.