-->
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.  [ 6 posts ] 
Author Message
 Post subject: IllegalArgumentException while accessing a @ManyToOne table
PostPosted: Mon Aug 21, 2006 12:47 pm 
Newbie

Joined: Mon Aug 21, 2006 12:44 pm
Posts: 12
Hello,

this is going to be my first post on this forum and I'll start with an issue I don't understand.

First this is what I have:

BO Class Mitarbeiter
Code:
@Entity
@Table(name = "gc_Tbl_Mitarbeiter")
public class Mitarbeiter {

    private Long mitarbeiterId;
    private String name;
    private Set<Ziel> ziele = new HashSet<Ziel>();

    public Mitarbeiter() {
    }

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long getMitarbeiterId() {
        return mitarbeiterId;
    }

    public void setMitarbeiterId(Long mitarbeiterId) {
        this.mitarbeiterId = mitarbeiterId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(mappedBy="mitarbeiter", cascade = {CascadeType.ALL}, targetEntity=Ziel.class)
    public Set<Ziel> getZiele() {
        return ziele;
    }

    public void setZiele(Set<Ziel> ziele) {
        this.ziele=ziele;
    }
   
    public void addZiel(Ziel ziel) {
        ziel.setMitarbeiter(this);
        ziele.add(ziel);
    }

}



and this is the Class Ziel:
Code:
@Entity
@Table(name = "gc_Tbl_Ziel")
public class Ziel {

    private Long zielId;
    private Integer zielGewichtung;
    private Mitarbeiter mitarbeiter;

    public Ziel() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getZielId() {
        return zielId;
    }

    public void setZielId(Long zielId) {
        this.zielId = zielId;
    }

    public Integer getZielGewichtung() {
        return zielGewichtung;
    }

    public void setZielGewichtung(Integer zielGewichtung) {
        this.zielGewichtung = zielGewichtung;
    }

    @ManyToOne
    public Mitarbeiter getMitarbeiter() {
        return mitarbeiter;
    }

    public void setMitarbeiter(Mitarbeiter mitarbeiter) {
        this.mitarbeiter = mitarbeiter;
    }
   
}



and in my Dao Class I want to do this:
Code:
        List liste = getHibernateTemplate().find("FROM Ziel z WHERE z.mitarbeiter = ?", mitarbeiterId);


But this will always result int this error message:
Code:
org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of de.guidecom.ssz.bo.impl.Mitarbeiter.mitarbeiterId; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of de.guidecom.ssz.bo.impl.Mitarbeiter.mitarbeiterId
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of de.guidecom.ssz.bo.impl.Mitarbeiter.mitarbeiterId
   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:3368)
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3084)
   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:77)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:333)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:826)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:817)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:813)
   at de.guidecom.ssz.persistenz.impl.HibernateZielDao.getAllZielByMitarbeiter(HibernateZielDao.java:14)
   at de.guidecom.ssz.persistenz.impl.HibernateZielDaoJUnitTest.testSaveZiel(HibernateZielDaoJUnitTest.java:91)
   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 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:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
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)
   ... 40 more



I am totally confused and I did spend the whole day with this without getting anywhere. I really dont understand what the problem is.

Maybee someone can spare a few minutes and have a look at this. Any help would be greatly apreciated.

Thanx a lot.
Santo

ps: hope you dont mind the german variable names.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 2:37 pm 
Regular
Regular

Joined: Fri Aug 18, 2006 2:40 pm
Posts: 51
Location: Metz, France
Can you try this instead:

implicit form:
Code:
List liste = getHibernateTemplate().find("FROM Ziel z WHERE z.mitarbeiter.mitarbeiterId = ?", mitarbeiterId);


explicit form:
Code:
List liste = getHibernateTemplate().find("FROM Ziel z inner join z.mitarbeiter as mitarbeiter WHERE mitarbeiter.mitarbeiterId = ?", mitarbeiterId);


My Mitarbeiter is a German ;-)

http://www.hibernate.org/hib_docs/v3/re ... yhql-joins

_________________
Denis
Don't forget to rate ... thanks.


Last edited by denis.etienne on Tue Aug 22, 2006 1:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 10:10 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And another victim of the horrid HibernateTemplate. Please remove it from your code. Hibernate has a perfectly usable API that needs no wrapping.

Code:
List liste = sessionFactory.getCurrentSession()
            .createQuery("from Ziel z where z.mitarbeiter.id = :mid")
            .setParameter("mid", mitarbeiterId)
            .list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 4:20 am 
Newbie

Joined: Mon Aug 21, 2006 12:44 pm
Posts: 12
Hello,

thank you both for your input.

This worked for me:
Code:
List liste = getHibernateTemplate().find("FROM Ziel z WHERE z.mitarbeiter.mitarbeiterId = ?", mitarbeiterId);


@Christian, Whats wrong with using the HibernateTemplate?

Thanks a lot
Santo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 8:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://blog.hibernate.org/cgi-bin/blosx ... frameworks


Top
 Profile  
 
 Post subject: Re: IllegalArgumentException while accessing a @ManyToOne table
PostPosted: Mon Nov 30, 2009 7:03 am 
Newbie

Joined: Mon Nov 30, 2009 6:31 am
Posts: 1
Hi Folks, I have a similar Problem, I'm using Qooxdoo as Framework, MSSQL-Server 2K5 as Database and XML for Mapping.
I'll post my code, maybe someone can help me to find the error because when I first wrote the stuff with german naming for values etc. it works fine. Then my boss ordered me to change everything to english and now it won't work anymore. Here is the code of the form called pickUpContract.form.xml:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/form.xsd">
<toolbar hasSaveButton="true" hasSaveAndExitButton="true" hasDeleteButton="true"/>
<headText>Abholauftrag</headText>
<backendKey>afbDaten</backendKey>
<dataHandler>afbDaten.logic.PickUpContract.PickUpContractLogic</dataHandler>
<conditions>
<condition id="0" setting="enabled" comparator="v" source="form">supplier</condition>
<condition id="1" setting="enabled" comparator="nv" source="form">supplier</condition>
</conditions>
<tabs>
<tab name="Abholauftrag">
<subForms>
<subForm type="single" mapping="afbDaten/dbm/PickUpContract.hbm.xml"
editable="true" javaClass="afbDaten.dbm.PickUpContract">
<hql keyField="id">from PickUpContract where id = :id</hql>
<formGrid>
<layout>
<columns>
<column pos="1">100</column>
<column pos="2">100</column>
<column pos="3">100</column>
<column pos="4">100</column>
<column pos="5">100</column>
</columns>
</layout>
<formFields>
<field><hidden binding="id" buffer="id"></hidden></field>
</formFields>
</formGrid>
</subForm>
</subForms>
</tab>


<tab name="AbholauftragDetails">
<subForms>
<subForm editable="true" type="endless" javaClass="afbDaten.dbm.PickUpContractDetails"
mapping="afbDaten/dbm/PickUpContractDetails.hbm.xml">
<hql keyField="id"> from PickUpContractDetails where pickUpContract=:id</hql>
<dataGrid pageSize="9" filter="true" deletable="true">
<headFields>
<field row="0" column="1"><label value="Menge" width="50"/></field>
<field row="0" column="5"><label value="Memo" width="240"/></field>
<field row="0" column="2"><label value="Typ" width="100"/></field>
<field row="0" column="3"><label value="Seriennummer" width="120"/></field>
<field row="0" column="4"><label value="Inventarnummer" width="120"/></field>
</headFields>
<formFields>
<field><hidden binding="client" buffer="client"></hidden></field>
<field row="0" column="1"><textField binding="quantity" width="50">
<validations>
<validation type="notNull">Das Feld darf nicht leer sein.</validation>
</validations>
</textField></field>
<field row="0" column="5"><textField binding="memo" width="240"></textField></field>
<field row="0" column="2">
<comboBoxPage binding="type" width="100" enabled="true">
<data>
<hql> from afbDaten.dbm.Category where client = :client</hql>
<boundField>type</boundField>
<shownFields>
<shownField text="GeräteTyp">type</shownField>
</shownFields>
</data>
</comboBoxPage>
</field>
<field row="0" column="3"><textField binding="serialNumber" width="120"/></field>
<field row="0" column="4"><textField binding="customerInventoryId" width="120"/></field>
<field> <!-- here starts the obvious wrong code -->
<hidden binding="pickUpContract">
<data>
<parameter>id</parameter>
<foreignClass>afbDaten.dbm.PickUpContract</foreignClass>
</data>
</hidden> <!-- here ends the code -->
</field>
</formFields>
</dataGrid>
</subForm>
</subForms>
</tab>
</tabs>
</form>

the next code is the code of the xml mapping class called PickUpContractDetails.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="afbDaten.dbm">
<class name="PickUpContractDetails" table="PickUpContractDetails" dynamic-update="true">
<id name="id" type="string">
<column name="id" />
<generator class="backend.NumberCircleGenerator" />
</id>
<property name="client" type="string">
<column name="client" not-null="false" length="20"></column>
</property>
<property name="quantity" type="string">
<column name="quantity" not-null="true" length="50"></column>
</property>
<property name="memo" type="string">
<column name="memo" not-null="false" length="500"></column>
</property>
<property name="serialNumber" type="string">
<column name="serialNumber" not-null="false" length="50"></column>
</property>
<property name="customerInventoryId" type="string">
<column name="customerInventoryId" not-null="false" length="50" /column>
</property>
<property name="saleStatus" type="string">
<column name="saleStatus" not-null="false" length="50"></column>
</property>

<!-- foreigen keys -->
<many-to-one name="pickUpContract" class="PickUpContract" fetch="select">
<column name="pickUpContract" not-null="true"></column>
</many-to-one>

<!-- the following foreign key is not hardwired so only combobox without mapping -->
<property name="type" type="string">
<column name="type" not-null="false" length="50"></column>
</property>
</class>
</hibernate-mapping>

the next code is the associated java file PickUpContractDetails.hbm.java:

package afbDaten.dbm;
public class PickUpContractDetails implements java.io.Serializable{

/**
*
*/
private static final long serialVersionUID = 3062108500774998374L;

private String quantity;
private String memo;
private String type;
private PickUpContract pickUpContract;
private String id;
private String serialNumber;
private String customerInventoryId;
private String client;
private String saleStatus;


public PickUpContractDetails(){

}

public PickUpContractDetails(String quantity, String memo, String type, PickUpContract pickUpContract, String id,
String saleStatus, String client, String customerInventoryId, String serialNumber){
this.quantity=quantity;
this.memo=memo;
this.type=type;
this.pickUpContract=pickUpContract;
this.id=id;
this.saleStatus=saleStatus;
this.client=client;
this.customerInventoryId=customerInventoryId;
this.serialNumber=serialNumber;
}

public PickUpContract getPickUpContract() {
return pickUpContract;
}

public void setPickUpContract(PickUpContract pickUpContract) {
this.pickUpContract = pickUpContract;
}

public String getMemo() {
return memo;
}

public void setMemo(String memo) {
this.memo = memo;
}

public String getQuantity() {
return quantity;
}

public void setQuantity(String quantity) {
this.quantity = quantity;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
public String getCustomerInventoryId() {
return customerInventoryId;
}

public void setCustomerInventoryId(String customerInventoryId) {
this.customerInventoryId = customerInventoryId;
}

public String getSerialNumber() {
return serialNumber;
}

public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}

public String getClient() {
return client;
}

public void setClient(String client) {
this.client = client;
}

public String getSaleStatus() {
return saleStatus;
}

public void setSaleStatus(String saleStatus) {
this.saleStatus = saleStatus;
}

}

When I use it like this I always get the errormessage which named this topic.
thanx for help


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