-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one forcemadure !
PostPosted: Sat Jun 03, 2006 2:58 pm 
Beginner
Beginner

Joined: Sat Nov 19, 2005 11:54 am
Posts: 22
Hello Please Help me quickly
i`ve written a many-to-one mapping it create correctly oracle tables but when i`m going to set courseid {thestudent.setCourseid(1L);} it ocures error see below :

Class Student :
public class Student {
private Long id;
private String name;
private String family;
private Long courseid;

public Student() {
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

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

public String getFamily() {
return family;
}

public void setFamily(String family) {
this.family = family;
}

public Long getCourseid() {
return courseid;
}

public void setCourseid(Long courseid) {
this.courseid = courseid;
}
}

The Mapping :
<?xml version='1.0' encoding='utf-8' standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="Student" table="Student">
<id name="id" column="ID">
<generator class="assigned"/>
</id>
<property name="name"/>
<property name="family"/>

<many-to-one
name="courseid"
column="courseid"
class="Course"
fetch="join"
access="property"
not-null="false"
not-found="ignore"
insert="true"
/>
</class>

</hibernate-mapping>

Class Course :
public class Course {
private Long id;
private String coursename;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getCoursename() {
return coursename;
}

public void setCoursename(String coursename) {
this.coursename = coursename;
}
}

Mapping:

<?xml version='1.0' encoding='utf-8' standalone="no"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="Course" table="Course">
<id name="id" column="ID" >
<generator class="assigned"/>
</id>
<property name="coursename"/>
</class>

</hibernate-mapping>

Main Class :
HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction();

Course theCourse = new Course();
theCourse.setId(1L);
theCourse.setCoursename("chemistry");
HibernateUtil.getSessionFactory().getCurrentSession().save(theCourse);

Student thestudent = new Student();
thestudent.setId(1L);
thestudent.setName("john");
thestudent.setFamily("smith");
//thestudent.setCourseid(1L);
HibernateUtil.getSessionFactory().getCurrentSession().save(thestudent);
HibernateUtil.getSessionFactory().getCurrentSession()
.getTransaction().commit();


The Erorr:

22:36:38,000 ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: Course, getter method of property: id

Full Message:

"I:\Program Files\Java\jdk1.5.0_04\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=I:\Program Files\JetBrains\IntelliJ IDEA 5.0\bin" -Dfile.encoding=windows-1256 -classpath "I:\Program Files\Java\jdk1.5.0_04\jre\lib\charsets.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\deploy.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\javaws.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\jce.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\jsse.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\plugin.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\rt.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\ext\localedata.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\ext\sunjce_provider.jar;I:\Program Files\Java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar;D:\fix\Final\classes;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\antlr-2.7.5H3.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\c3p0-0.9.0.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\asm-attrs.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\commons-collections-2.1.1.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\log4j-1.2.11.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\cglib-2.1.2.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\dom4j-1.6.1.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\ehcache-1.1.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\jta.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\asm.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\hibernate3.jar;I:\hibernate\hibernate-3.1rc2\hibernate-3.1\lib\commons-logging-1.0.4.jar;E:\oracle\ora90\jdbc\lib\classes12.jar;I:\Program Files\JetBrains\IntelliJ IDEA 5.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain Runable store
22:36:35,796 INFO Environment:474 - Hibernate 3.1 rc2
22:36:35,796 INFO Environment:504 - hibernate.properties not found
22:36:35,812 INFO Environment:520 - using CGLIB reflection optimizer
22:36:35,812 INFO Environment:550 - using JDK 1.4 java.sql.Timestamp handling
22:36:35,906 INFO Configuration:1257 - configuring from resource: /hibernate.cfg.xml
22:36:35,906 INFO Configuration:1234 - Configuration resource: /hibernate.cfg.xml
22:36:36,062 INFO Configuration:460 - Reading mappings from resource: Course.hbm.xml
22:36:36,218 INFO HbmBinder:266 - Mapping class: Course -> Course
22:36:36,250 INFO Configuration:460 - Reading mappings from resource: Student.hbm.xml
22:36:36,312 INFO HbmBinder:266 - Mapping class: Student -> Student
22:36:36,406 INFO Configuration:1368 - Configured SessionFactory: null
22:36:36,406 INFO Configuration:1014 - processing extends queue
22:36:36,406 INFO Configuration:1018 - processing collection mappings
22:36:36,406 INFO Configuration:1027 - processing association property references
22:36:36,406 INFO Configuration:1049 - processing foreign key constraints
22:36:36,421 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
22:36:36,421 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
22:36:36,421 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
22:36:36,421 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:ict
22:36:36,421 INFO DriverManagerConnectionProvider:86 - connection properties: {user=system, password=****}
22:36:36,828 INFO SettingsFactory:77 - RDBMS: Oracle, version: Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option
JServer Release 9.0.1.1.1 - Production
22:36:36,828 INFO SettingsFactory:78 - JDBC driver: Oracle JDBC driver, version: 9.0.1.1.0
22:36:36,843 INFO Dialect:100 - Using dialect: org.hibernate.dialect.Oracle9Dialect
22:36:36,859 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
22:36:36,859 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
22:36:36,859 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
22:36:36,859 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
22:36:36,859 INFO SettingsFactory:136 - JDBC batch size: 15
22:36:36,859 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
22:36:36,875 INFO SettingsFactory:144 - Scrollable result sets: enabled
22:36:36,890 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): disabled
22:36:36,890 INFO SettingsFactory:160 - Connection release mode: auto
22:36:36,890 INFO SettingsFactory:187 - Default batch fetch size: 1
22:36:36,890 INFO SettingsFactory:191 - Generate SQL with comments: disabled
22:36:36,890 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
22:36:36,890 INFO SettingsFactory:338 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
22:36:36,890 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
22:36:36,968 INFO SettingsFactory:203 - Query language substitutions: {}
22:36:36,968 INFO SettingsFactory:209 - Second-level cache: enabled
22:36:36,968 INFO SettingsFactory:213 - Query cache: disabled
22:36:36,968 INFO SettingsFactory:325 - Cache provider: org.hibernate.cache.EhCacheProvider
22:36:36,984 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
22:36:36,984 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
22:36:36,984 INFO SettingsFactory:257 - Echoing all SQL to stdout
22:36:36,984 INFO SettingsFactory:264 - Statistics: disabled
22:36:36,984 INFO SettingsFactory:268 - Deleted entity synthetic identifier rollback: disabled
22:36:36,984 INFO SettingsFactory:283 - Default entity-mode: POJO
22:36:37,140 INFO SessionFactoryImpl:155 - building session factory
22:36:37,156 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/I:/hibernate/hibernate-3.1rc2/hibernate-3.1/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
22:36:37,531 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
22:36:37,531 INFO Configuration:1014 - processing extends queue
22:36:37,531 INFO Configuration:1018 - processing collection mappings
22:36:37,531 INFO Configuration:1027 - processing association property references
22:36:37,531 INFO Configuration:1049 - processing foreign key constraints
22:36:37,531 INFO Configuration:1014 - processing extends queue
22:36:37,531 INFO Configuration:1018 - processing collection mappings
22:36:37,531 INFO Configuration:1027 - processing association property references
22:36:37,531 INFO Configuration:1049 - processing foreign key constraints
22:36:37,546 INFO SchemaExport:153 - Running hbm2ddl schema export
22:36:37,546 DEBUG SchemaExport:171 - import file not found: /import.sql
22:36:37,546 INFO SchemaExport:180 - exporting generated schema to database
22:36:37,546 DEBUG SchemaExport:283 - drop table Course cascade constraints
22:36:37,718 DEBUG SchemaExport:283 - drop table Student cascade constraints
22:36:37,765 DEBUG SchemaExport:283 - create table Course (ID number(19,0) not null, coursename varchar2(255 char), primary key (ID))
22:36:37,796 DEBUG SchemaExport:283 - create table Student (ID number(19,0) not null, name varchar2(255 char), family varchar2(255 char), courseid number(19,0), primary key (ID))
22:36:37,812 DEBUG SchemaExport:283 - alter table Student add constraint FKF3371A1B62B31EB1 foreign key (courseid) references Course
22:36:37,828 INFO SchemaExport:200 - schema export complete
22:36:37,843 INFO SessionFactoryImpl:432 - Checking 0 named queries
22:36:38,000 ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: Course, getter method of property: id
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of Course.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:3256)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2982)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:137)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:69)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:47)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:263)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:524)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:510)
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.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:271)
at $Proxy0.save(Unknown Source)
at Runable.createAndStoreEvent(Runable.java:80)
at Runable.main(Runable.java:38)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
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)
... 31 more


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 3:46 am 
Newbie

Joined: Wed Oct 06, 2004 2:49 am
Posts: 12
Saeed ,

When you map many-to-one associations you acctually have to have a many-to-one association in your java classes. So don't say your Student has a 'private Long courseid', but a 'private Course course'. This is rather the heart of ORM....The clue in your stacktrace is:

Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class

When hibernate uses reflection with a Course instance where your java code expects a Long.


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