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.