I have a class called TransportJob which has a field called jobId which is a primary key) and another class called TransportJobSegment which has jobId as a foreign key. A TransportJob has many TransportJobSegments.
I am able to save the TransportJob in its table, but when I save the TransportJobSegment in its table, I get an IllegalArgumentException
Hibernate version:3.0
Mapping documents:
Mapping file for TrasportJob:
<?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>
<class name="TransportJob" table="jobs">
<id name="jobId" type="string">
<column name="job_id" length="50"/>
</id>
<property name="dependantJobId" type="string">
<column name="dependent_job_id" length="50" not-null="false" sql-type="varchar(32)"/>
</property>
<property name="jobSource" type="string">
<column name="job_source" length="50" not-null="false" sql-type="varchar(50)"/>
</property>
<property name="jobValid" type="boolean">
<column name="job_valid" not-null="true" sql-type="tinyint"/>
</property>
<property name="segmentTotal" column="segment_total" type="int"/>
<property name="creationTimestamp" type="java.util.Date">
<column name="creation_date" length="50" not-null="true" sql-type="varchar(50)"/>
</property>
<property name="revisionNumber" column="revision_number" type="long"/>
<property name="repositoryURL" type="string">
<column name="repository_url" length="50" not-null="true" sql-type="varchar(50)"/>
</property>
<property name="repositoryUUID" type="string">
<column name="repository_uuid" length="50" not-null="true"/>
</property>
</class>
</hibernate-mapping>
Mapping file for TransportJobSegment:
<?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>
<class name="TransportJobSegment" table="segments">
<id name="segmentId" type="string">
<column name="segment_id" length="50"/>
</id>
<many-to-one name="jobId" class="TransportJob" column="job_id"/>
<property name="segmentNumber" column="segment_number" type="int"/>
<property name="changeAgent" type="string">
<column name="change_agent" length="50" not-null="false" sql-type="varchar(32)"/>
</property>
<property name="changePurpose" type="string">
<column name="change_purpose" length="50" not-null="false" sql-type="varchar(50)"/>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session hibernateSession = this.hibernateSessionFactory.openSession();
try {
Transaction tx = hibernateSession.beginTransaction();
hibernateSession.save(job);
tx.commit();
} catch (HibernateException ex){
System.out.println("Hibernate Exception: Could not save the job to the database.");
}
/*
* Save the jobSegment
*/
Set<TransportJobSegment> segmentSet = job.getSegmentSet();
/*
* Get the first jobSegment. At this point only one jobSegment
* will be present in TransportJob List
*/
Iterator iter = segmentSet.iterator();
TransportJobSegment jobSegment = (TransportJobSegment)iter.next();
try {
Transaction tx2 = hibernateSession.beginTransaction();
hibernateSession.save(jobSegment);
tx2.commit();
hibernateSession.close();
}catch(HibernateException ex){
System.out.println(ex);
System.out.println("Hibernate Exception: Could not save the segment to the database.");
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
DEBUG - Returning cached instance of singleton bean 'jobDAO'
DEBUG - Returning cached instance of singleton bean 'jobSegmentDAO'
DEBUG - opened session at timestamp: 4655009582526464
DEBUG - begin
DEBUG - opening JDBC connection
DEBUG - total checked-out connections: 0
DEBUG - using pooled JDBC connection, pool size: 0
DEBUG - current autocommit status: false
DEBUG - after transaction begin
DEBUG - saving transient instance
DEBUG - generated identifier: CcdhDKst473z2FnHQ5sZNrCPKhBSXzb3, using strategy: org.hibernate.id.Assigned
DEBUG - saving [TransportJob#CcdhDKst473z2FnHQ5sZNrCPKhBSXzb3]
DEBUG - commit
DEBUG - automatically flushing session
DEBUG - flushing session
DEBUG - processing flush-time cascades
DEBUG - dirty checking collections
DEBUG - Flushing entities and processing referenced collections
DEBUG - Processing unreferenced collections
DEBUG - Scheduling collection removes/(re)creates/updates
DEBUG - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
DEBUG - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG - listing entities:
DEBUG - TransportJob{repositoryURL=repositoryURL, segmentTotal=3, dependantJobId=dependantJobID, revisionNumber=10, repositoryUUID=repositoryUUID, creationTimestamp=2006-01-05 11:02:28, jobValid=false, jobId=CcdhDKst473z2FnHQ5sZNrCPKhBSXzb3, jobSource=jobSource}
DEBUG - executing flush
DEBUG - Inserting entity: [TransportJob#CcdhDKst473z2FnHQ5sZNrCPKhBSXzb3]
DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - insert into jobs (dependent_job_id, job_source, job_valid, segment_total, creation_date, revision_number, repository_url, repository_uuid, job_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into jobs (dependent_job_id, job_source, job_valid, segment_total, creation_date, revision_number, repository_url, repository_uuid, job_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
DEBUG - preparing statement
DEBUG - Dehydrating entity: [TransportJob#CcdhDKst473z2FnHQ5sZNrCPKhBSXzb3]
DEBUG - binding 'dependantJobID' to parameter: 1
DEBUG - binding 'jobSource' to parameter: 2
DEBUG - binding 'false' to parameter: 3
DEBUG - binding '3' to parameter: 4
DEBUG - binding '2006-01-05 11:02:28' to parameter: 5
DEBUG - binding '10' to parameter: 6
DEBUG - binding 'repositoryURL' to parameter: 7
DEBUG - binding 'repositoryUUID' to parameter: 8
DEBUG - binding 'CcdhDKst473z2FnHQ5sZNrCPKhBSXzb3' to parameter: 9
DEBUG - Adding to batch
DEBUG - Executing batch size: 1
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - post flush
DEBUG - before transaction completion
DEBUG - before transaction completion
DEBUG - committed JDBC Connection
DEBUG - after transaction completion
DEBUG - aggressively releasing JDBC connection
DEBUG - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG - returning connection to pool, pool size: 1
DEBUG - after transaction completion
DEBUG - begin
DEBUG - opening JDBC connection
DEBUG - total checked-out connections: 0
DEBUG - using pooled JDBC connection, pool size: 0
DEBUG - current autocommit status: false
DEBUG - after transaction begin
DEBUG - saving transient instance
DEBUG - generated identifier: segmentID, using strategy: org.hibernate.id.Assigned
DEBUG - saving [TransportJobSegment#segmentID]
ERROR - IllegalArgumentException in class: TransportJob, getter method of property: jobId
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of TransportJob.jobId
Hibernate Exception: Could not save the segment to the database.
|