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.  [ 1 post ] 
Author Message
 Post subject: Error: object is not an instance of declaring class
PostPosted: Mon Jun 02, 2008 2:06 am 
Newbie

Joined: Sat May 24, 2008 6:20 am
Posts: 6
BuyWritePosition is a subclass of OptionPosition, but they are mapped to the same database table option_position. Here is the OptionPosition.hbm.xml:

<hibernate-mapping default-lazy="false">

<class name="com.ameraust.investor.option.strategy.OptionPosition" table="option_position" abstract="true">
<id name="id" type="int" column="id">
<generator class="increment"/>
</id>

<discriminator column="option_position_ref_id" type="int"/>

...

<subclass name="com.ameraust.investor.option.strategy.BuyWritePosition" discriminator-value="1"/>
</class>
</hibernate-mapping>

Here are the definitions of the classes:


public abstract class OptionPosition {

private int id;
...
}

public class BuyWritePosition extends OptionPosition {
...
}

When trying to save a BuyWritePosition object:

OptionPosition optionPosition = new BuyWritePosition(...);

session.save(optionPosition);

Got the following error.

It seems the error happened with the primary key -- id. No idea why.

Thanks,


14:57:47,656 ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: com.ameraust.investor.option.strategy.OptionPosition, getter method of property: id
14:57:47,656 ERROR AmeraustInvestor:53 - Error
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.ameraust.investor.option.strategy.OptionPosition.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at com.ameraust.investor.database.HibernateUtil.<clinit>(HibernateUtil.java:29)
at com.ameraust.investor.database.OptionPositionDBProcessor.create(OptionPositionDBProcessor.java:118)
at com.ameraust.investor.AmeraustInvestor.saveBuyWriteToDB(AmeraustInvestor.java:79)
at com.ameraust.investor.AmeraustInvestor.main(AmeraustInvestor.java:53)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 12 more


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

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.