-->
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.  [ 3 posts ] 
Author Message
 Post subject: Strange IllegalArgumentException apparition!!
PostPosted: Fri Jan 30, 2009 6:06 am 
Newbie

Joined: Fri Jan 30, 2009 4:05 am
Posts: 2
Location: Málaga Valley (Spain)
I have a problem with an entity.

I'm modeling many pojos. I'm mapping them with JPA.
Before the problem I had a pojo (lets call it Pojo01). Pojo01 maps a relationship between Pojo02 and Pojo03 and adds one more property:

Code:
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = {
        "POJO_02",
        "POJO_03" }) })
public class Pojo01 implements Serializable {

private Long id;
private Pojo02 pojo02;
private Pojo03 pojo03;
private Boolean good;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "generator_pojo01")
    @SequenceGenerator(name = "generator_pojo01", sequenceName = "SEQ_POJO_01")
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
   
    protected void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(targetEntity = Pojo02.class, cascade = { CascadeType.PERSIST,
    CascadeType.MERGE })
    @JoinColumn(name = "POJO_02", nullable = false, updatable = false)
    public Pojo02 getPojo02() {
        return pojo02;
    }
   
    public setPojo02(Pojo02 pojo02){
       this.pojo02 = pojo02;
    }
   
   
    @ManyToOne(targetEntity = Pojo03.class, cascade = { CascadeType.PERSIST,
    CascadeType.MERGE })
    @JoinColumn(name = "POJO_03", nullable = false, updatable = false)
    public Pojo03 getPojo03() {
        return pojo03;
    }
   
    public setPojo03(Pojo03 pojo03){
       this.pojo03 = pojo03;
    }
   
    @Column(name = "GOOD")
    public Boolean getGood() {
        return good;
    }
   
    protected void setGood(Boolean good) {
        this.good = good;
    }
}


Pojo03 also has a realtionship with Pojo04:

Code:
@Entity
public class Pojo03 implements Serializable {

private Long id;
private Pojo04 pojo04;
/* It has more properties */

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "generator_pojo03")
    @SequenceGenerator(name = "generator_pojo03", sequenceName = "SEQ_POJO_03")
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
   
    protected void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(targetEntity = Usuario.class, cascade = { CascadeType.PERSIST,
    CascadeType.MERGE })
    @JoinColumn(name = "POJO_04", nullable = false, updatable = false)
    public Pojo04 getPojo04() {
        return pojo04;
    }
   
    public setPojo04(Pojo04 pojo04){
       this.pojo04 = pojo04;
    }
}


I have tested the DAO layer and it works fine.

Now I tell my problem.

I create a new pojo (PojoX) it implements the relationship between Pojo01 and other one (Pojo05).

Code:
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = {
        "POJO_01",
        "POJO_05" }) })
public class PojoX implements Serializable {

private Long id;
private Pojo01 pojo01;
private Pojo05 pojo05;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "generator_pojox")
    @SequenceGenerator(name = "generator_pojox", sequenceName = "SEQ_POJO_X")
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
   
    protected void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(targetEntity = Pojo01.class, cascade = { CascadeType.PERSIST,
    CascadeType.MERGE })
    @JoinColumn(name = "POJO_01", nullable = false, updatable = false)
    public Pojo01 getPojo01() {
        return pojo01;
    }
   
    public setPojo01(Pojo01 pojo01){
       this.pojo01 = pojo01;
    }
   
   
    @ManyToOne(targetEntity = Pojo05.class, cascade = { CascadeType.PERSIST,
    CascadeType.MERGE })
    @JoinColumn(name = "POJO_05", nullable = false, updatable = false)
    public Pojo05 getPojo05() {
        return pojo05;
    }
   
    public setPojo05(Pojo05 pojo05){
       this.pojo05 = pojo05;
    }
   
}


Well, when I test the DAO, when I do a DaoPojoX.save(pojox) it fails. The trace is:

Code:
-------------------------------------------------------------------------------
Test set: test.dao.hibernate.PojoXDaoTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.078 sec <<< FAILURE!
testAddAndRemovePojoX(test.dao.hibernate.PojoXDaoTest)  Time elapsed: 0.062 sec  <<< ERROR!
test.exception.MyOwnException: ERROR_GENERAL_BD
   at test.exception.ExceptionUtil.createMyOwnException(ExceptionUtil.java:124)
   at test.dao.hibernate.GenericDAOImpl.save(GenericDAOImpl.java:221)
   at test.dao.hibernate.PojoXDaoTest.testAddAndRemovePojoX(PojoXDaoTest.java:50)
   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 junit.framework.TestCase.runTest(TestCase.java:168)
   at junit.framework.TestCase.runBare(TestCase.java:134)
   at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
   at junit.framework.TestResult$1.protect(TestResult.java:110)
   at junit.framework.TestResult.runProtected(TestResult.java:128)
   at junit.framework.TestResult.run(TestResult.java:113)
   at junit.framework.TestCase.run(TestCase.java:124)
   at junit.framework.TestSuite.runTest(TestSuite.java:232)
   at junit.framework.TestSuite.run(TestSuite.java:227)
   at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
   at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
   at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
   at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
   at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
   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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
   at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of test.model.Pojo03.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.model.Pojo03.id
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
   at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:824)
   at test.dao.hibernate.GenericDAOImpl.save(GenericDAOImpl.java:218)
   ... 25 more
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.model.Pojo03.id
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3596)
   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:98)
   at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
   at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
   at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
   at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:178)
   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
   at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
   at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:827)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
   ... 28 more
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(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
   ... 47 more


IllegalArgumentException occurred calling getter of test.model.Pojo03.id ?!?!?!?!


Last edited by AleSV on Fri Jan 30, 2009 11:10 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 10:51 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Hi,

I'm not sure whether it is significant, but it might be clearer if your POJO01 has its own sequence for generating ids.

According to the code that you included in your post, it appears to be using POJO01's sequence:

@SequenceGenerator(name = "generator_pojo02", sequenceName = "SEQ_POJO_02")


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 11:02 am 
Newbie

Joined: Fri Jan 30, 2009 4:05 am
Posts: 2
Location: Málaga Valley (Spain)
oops!! It has bean a copy/paste mistake.

you are right and it really has it's own sequence.

I have corrected it.

Thanks very much anyway!!!


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