Hello, I have a table with a required field (submitter_name) and I am trying to save an object which has that property populated. I receive an error because the database is telling me that the field can't be null (which it isn't). Can somebody please help me with this problem? All of the related information is below. Thanks very much.
Joe
Hibernate version: 2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.myadbox.bo">
<class name="Form" table="form">
<id
column="form_id"
name="Id"
type="java.lang.Long"
>
<generator class="com.myadbox.bo.identity.BlockGenerator" />
</id>
<property
column="amt_paid"
length="3"
name="AmountPaid"
not-null="false"
type="big_decimal"
/>
<many-to-one
class="MessageBox"
column="message_box_id"
name="MessageBox"
not-null="true"
/>
<property
column="created_date"
length="19"
name="CreatedDate"
not-null="true"
type="timestamp"
/>
<property
column="email_address"
length="100"
name="EmailAddress"
not-null="false"
type="string"
/>
<property
column="phone_number"
length="25"
name="PhoneNumber"
not-null="false"
type="string"
/>
<joined-subclass name="FormRentalApplication" table="form_rental_application">
<key column="form_id" />
<property
column="submitter_name"
length="100"
name="SubmitterName"
not-null="true"
type="string"
/>
<property
column="not_paid_rent"
length="1"
name="NotPaidRent"
not-null="true"
type="true_false"
/>
<property
column="ca_landlord_phone"
length="10"
name="CurrentAddressLandlordPhone"
not-null="false"
type="string"
/>
<property
column="ca_zip"
length="9"
name="CurrentAddressZip"
not-null="true"
type="string"
/>
<property
column="pa_line2"
length="100"
name="PreviousAddressLine2"
not-null="false"
type="string"
/>
<property
column="ct_social_security_number"
length="9"
name="CoTenantSocialSecurityNumber"
not-null="false"
type="string"
/>
<property
column="ct_gross_income"
length="7"
name="CoTenantGrossIncome"
not-null="false"
type="big_decimal"
/>
<property
column="ca_years"
length="11"
name="CurrentAddressYears"
not-null="true"
type="integer"
/>
<property
column="employer_address"
length="100"
name="EmployerAddress"
not-null="true"
type="string"
/>
<property
column="pa_landlord_phone"
length="10"
name="PreviousAddressLandlordPhone"
not-null="false"
type="string"
/>
<property
column="pa_phone"
length="10"
name="PreviousAddressPhone"
not-null="false"
type="string"
/>
<property
column="ct_employer_address"
length="100"
name="CoTenantEmployerAddress"
not-null="false"
type="string"
/>
<property
column="ct_drivers_license_number"
length="40"
name="CoTenantDriversLicenseNumber"
not-null="false"
type="string"
/>
<property
column="ca_city"
length="60"
name="CurrentAddressCity"
not-null="true"
type="string"
/>
<property
column="gross_income"
length="7"
name="GrossIncome"
not-null="true"
type="big_decimal"
/>
<property
column="ca_line1"
length="80"
name="CurrentAddressLine1"
not-null="true"
type="string"
/>
<property
column="ct_employer_name"
length="100"
name="CoTenantEmployerName"
not-null="false"
type="string"
/>
<property
column="pa_state"
length="2"
name="PreviousAddressState"
not-null="false"
type="string"
/>
<property
column="ct_birth_date"
length="10"
name="CoTenantBirthDate"
not-null="false"
type="date"
/>
<property
column="occupants"
length="11"
name="Occupants"
not-null="true"
type="integer"
/>
<property
column="supervisor_name"
length="100"
name="SupervisorName"
not-null="true"
type="string"
/>
<property
column="time_at_job"
length="25"
name="TimeAtJob"
not-null="true"
type="string"
/>
<property
column="ca_landlord_name"
length="100"
name="CurrentAddressLandlordName"
not-null="false"
type="string"
/>
<property
column="ct_supervisor_name"
length="100"
name="CoTenantSupervisorName"
not-null="false"
type="string"
/>
<property
column="birth_date"
length="10"
name="BirthDate"
not-null="true"
type="date"
/>
<property
column="pa_city"
length="60"
name="PreviousAddressCity"
not-null="false"
type="string"
/>
<property
column="employer_phone"
length="10"
name="EmployerPhone"
not-null="true"
type="string"
/>
<property
column="employer_name"
length="100"
name="EmployerName"
not-null="true"
type="string"
/>
<property
column="social_security_number"
length="9"
name="SocialSecurityNumber"
not-null="true"
type="string"
/>
<property
column="pa_rent"
length="4"
name="PreviousAddressRent"
not-null="false"
type="big_decimal"
/>
<property
column="have_pets"
length="1"
name="HavePets"
not-null="true"
type="true_false"
/>
<property
column="ct_employer_phone"
length="10"
name="CoTenantEmployerPhone"
not-null="false"
type="string"
/>
<property
column="ca_rent"
length="4"
name="CurrentAddressRent"
not-null="false"
type="big_decimal"
/>
<property
column="pa_years"
length="11"
name="PreviousAddressYears"
not-null="false"
type="integer"
/>
<property
column="job_position"
length="50"
name="JobPosition"
not-null="true"
type="string"
/>
<property
column="pa_zip"
length="9"
name="PreviousAddressZip"
not-null="false"
type="string"
/>
<property
column="ct_job_position"
length="50"
name="CoTenantJobPosition"
not-null="false"
type="string"
/>
<property
column="ct_name"
length="100"
name="CoTenantName"
not-null="false"
type="string"
/>
<property
column="had_bankruptcy"
length="1"
name="HadBankruptcy"
not-null="true"
type="true_false"
/>
<property
column="pa_line1"
length="100"
name="PreviousAddressLine1"
not-null="false"
type="string"
/>
<property
column="pa_reason_for_leaving"
length="255"
name="PreviousAddressReasonForLeaving"
not-null="false"
type="string"
/>
<property
column="pa_landlord_name"
length="100"
name="PreviousAddressLandlordName"
not-null="false"
type="string"
/>
<property
column="been_evicted"
length="1"
name="BeenEvicted"
not-null="true"
type="true_false"
/>
<property
column="drivers_license_number"
length="40"
name="DriversLicenseNumber"
not-null="false"
type="string"
/>
<property
column="smoke_cigarettes"
length="1"
name="SmokeCigarettes"
not-null="true"
type="true_false"
/>
<property
column="ca_line2"
length="100"
name="CurrentAddressLine2"
not-null="false"
type="string"
/>
<property
column="pets_description"
length="255"
name="PetsDescription"
not-null="false"
type="string"
/>
<property
column="ct_time_at_job"
length="25"
name="CoTenantTimeAtJob"
not-null="false"
type="string"
/>
<property
column="ca_state"
length="2"
name="CurrentAddressState"
not-null="false"
type="string"
/>
<set name="References">
<key column="form_id" />
<one-to-many class="RentalApplicationReference"/>
</set>
</joined-subclass>
<joined-subclass name="FormResume" table="form_resume">
<key column="form_id" />
<property
column="address_line_1"
length="100"
name="AddressLine1"
not-null="true"
type="string"
/>
<property
column="professional_profile"
length="255"
name="ProfessionalProfile"
not-null="false"
type="string"
/>
<property
column="address_line_2"
length="100"
name="AddressLine2"
not-null="false"
type="string"
/>
<property
column="last_name"
length="50"
name="LastName"
not-null="true"
type="string"
/>
<property
column="objective"
length="255"
name="Objective"
not-null="false"
type="string"
/>
<property
column="middle_initial"
length="1"
name="MiddleInitial"
not-null="false"
type="string"
/>
<property
column="state"
length="2"
name="State"
not-null="true"
type="string"
/>
<property
column="zip"
length="9"
name="Zip"
not-null="true"
type="string"
/>
<property
column="email_address"
length="100"
name="EmailAddress"
not-null="false"
type="string"
/>
<property
column="first_name"
length="20"
name="FirstName"
not-null="true"
type="string"
/>
<property
column="city"
length="50"
name="City"
not-null="true"
type="string"
/>
<set name="Education">
<key column="form_id" />
<one-to-many class="ResumeEducation"/>
</set>
<set name="Experience">
<key column="form_id" />
<one-to-many class="ResumeExperience"/>
</set>
<set name="References">
<key column="form_id" />
<one-to-many class="ResumeReference"/>
</set>
<set name="Skills">
<key column="form_id" />
<one-to-many class="ResumeSkill"/>
</set>
</joined-subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction t = null;
Session s = null;
try {
s = getSessionFactory().openSession();;
t = s.beginTransaction();
FormRentalApplication ra = new FormRentalApplication();
ra.setMessageBox(messageBox);
ra.setCreatedDate(new Date());
ra.setSubmitterName("Submitter Name");
ra.setPhoneNumber("123456789");
ra.setDriversLicenseNumber("NC DL");
ra.setBirthDate(SimpleDateFormat.getDateInstance(DateFormat.SHORT).parse("7/21/75"));
ra.setSocialSecurityNumber("451895926");
ra.setCurrentAddressLine1("123 Oak St.");
ra.setCurrentAddressCity("Waxhaw");
ra.setCurrentAddressState("NC");
ra.setCurrentAddressZip("28173");
ra.setCurrentAddressYears(new Integer(1));
ra.setEmployerName("Wachovia");
ra.setEmployerAddress("Tryon St.");
ra.setEmployerPhone("123456789");
ra.setTimeAtJob("2 1/2 years");
ra.setSupervisorName("John Doe");
ra.setJobPosition("Architect");
ra.setGrossIncome(new BigDecimal(20000));
ra.setOccupants(new Integer(2));
ra.setSmokeCigarettes(true);
ra.setHavePets(true);
ra.setHadBankruptcy(true);
ra.setBeenEvicted(true);
ra.setNotPaidRent(true);
s.save(ra);
t.commit();
}
catch (HibernateException e) {
if (null != t) t.rollback();
throw e;
}
finally {
s.close();
}
Full stack trace of any exception that occurs:
org.postgresql.util.PSQLException: ERROR: null value in column "submitter_name" violates not-null constraint
at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)
at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:152)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:100)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:517)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:273)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:335)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:461)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:433)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
Name and version of the database you are using:
postgresql 7.3
The generated SQL (show_sql=true):
insert into form (amt_paid, message_box_id, created_date, email_address, phone_number, form_id) values (?, ?, ?, ?, ?, ?)
insert into form_rental_application (submitter_name, not_paid_rent, ca_landlord_phone, ca_zip, pa_line2, ct_social_security_number, ct_gross_income, ca_years, employer_address, pa_landlord_phone, pa_phone, ct_employer_address, ct_drivers_license_number, ca_city, gross_income, ca_line1, ct_employer_name, pa_state, ct_birth_date, occupants, supervisor_name, time_at_job, ca_landlord_name, ct_supervisor_name, birth_date, pa_city, employer_phone, employer_name, social_security_number, pa_rent, have_pets, ct_employer_phone, ca_rent, pa_years, job_position, pa_zip, ct_job_position, ct_name, had_bankruptcy, pa_line1, pa_reason_for_leaving, pa_landlord_name, been_evicted, drivers_license_number, smoke_cigarettes, ca_line2, pets_description, ct_time_at_job, ca_state, form_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
20041002 02:12:17 DEBUG [] - Inserting entity: [com.myadbox.bo.FormRentalApplication#4]
20041002 02:12:17 DEBUG [] - about to open: 0 open PreparedStatements, 0 open ResultSets
20041002 02:12:17 DEBUG [] - insert into form (amt_paid, message_box_id, created_date, email_address, phone_number, form_id) values (?, ?, ?, ?, ?, ?)
20041002 02:12:17 DEBUG [] - preparing statement
20041002 02:12:17 DEBUG [] - about to open: 1 open PreparedStatements, 0 open ResultSets
20041002 02:12:17 DEBUG [] - insert into form_rental_application (submitter_name, not_paid_rent, ca_landlord_phone, ca_zip, pa_line2, ct_social_security_number, ct_gross_income, ca_years, employer_address, pa_landlord_phone, pa_phone, ct_employer_address, ct_drivers_license_number, ca_city, gross_income, ca_line1, ct_employer_name, pa_state, ct_birth_date, occupants, supervisor_name, time_at_job, ca_landlord_name, ct_supervisor_name, birth_date, pa_city, employer_phone, employer_name, social_security_number, pa_rent, have_pets, ct_employer_phone, ca_rent, pa_years, job_position, pa_zip, ct_job_position, ct_name, had_bankruptcy, pa_line1, pa_reason_for_leaving, pa_landlord_name, been_evicted, drivers_license_number, smoke_cigarettes, ca_line2, pets_description, ct_time_at_job, ca_state, form_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
20041002 02:12:17 DEBUG [] - preparing statement
20041002 02:12:17 DEBUG [] - Dehydrating entity: [com.myadbox.bo.FormRentalApplication#4]
20041002 02:12:17 DEBUG [] - preparing statement
20041002 02:12:17 DEBUG [] - Dehydrating entity: [com.myadbox.bo.FormRentalApplication#4]
20041002 02:12:17 DEBUG [] - binding null to parameter: 1
20041002 02:12:17 DEBUG [] - binding '1' to parameter: 2
20041002 02:12:17 DEBUG [] - binding '2004-10-02 02:12:17' to parameter: 3
20041002 02:12:17 DEBUG [] - binding null to parameter: 4
20041002 02:12:17 DEBUG [] - binding '123456789' to parameter: 5
20041002 02:12:17 DEBUG [] - binding '4' to parameter: 6
20041002 02:12:17 DEBUG [] - binding 'Submitter Name' to parameter: 1
20041002 02:12:17 DEBUG [] - binding 'true' to parameter: 2
20041002 02:12:17 DEBUG [] - binding null to parameter: 3
20041002 02:12:17 DEBUG [] - binding '28173' to parameter: 4
20041002 02:12:17 DEBUG [] - binding null to parameter: 5
20041002 02:12:17 DEBUG [] - binding null to parameter: 6
20041002 02:12:17 DEBUG [] - binding null to parameter: 7
20041002 02:12:17 DEBUG [] - binding '1' to parameter: 8
20041002 02:12:17 DEBUG [] - binding 'Tryon St.' to parameter: 9
20041002 02:12:17 DEBUG [] - binding null to parameter: 10
20041002 02:12:17 DEBUG [] - binding null to parameter: 11
20041002 02:12:17 DEBUG [] - binding null to parameter: 12
20041002 02:12:17 DEBUG [] - binding null to parameter: 13
20041002 02:12:17 DEBUG [] - binding 'Waxhaw' to parameter: 14
20041002 02:12:17 DEBUG [] - binding '20000' to parameter: 15
20041002 02:12:17 DEBUG [] - binding '123 Oak St.' to parameter: 16
20041002 02:12:17 DEBUG [] - binding null to parameter: 17
20041002 02:12:17 DEBUG [] - binding null to parameter: 18
20041002 02:12:17 DEBUG [] - binding null to parameter: 19
20041002 02:12:17 DEBUG [] - binding '2' to parameter: 20
20041002 02:12:17 DEBUG [] - binding 'John Doe' to parameter: 21
20041002 02:12:17 DEBUG [] - binding '2 1/2 years' to parameter: 22
20041002 02:12:17 DEBUG [] - binding null to parameter: 23
20041002 02:12:17 DEBUG [] - binding null to parameter: 24
20041002 02:12:17 DEBUG [] - binding '21 July 1975' to parameter: 25
20041002 02:12:17 DEBUG [] - binding null to parameter: 26
20041002 02:12:17 DEBUG [] - binding '123456789' to parameter: 27
20041002 02:12:17 DEBUG [] - binding 'Acme' to parameter: 28
20041002 02:12:17 DEBUG [] - binding '451895926' to parameter: 29
20041002 02:12:17 DEBUG [] - binding null to parameter: 30
20041002 02:12:17 DEBUG [] - binding 'true' to parameter: 31
20041002 02:12:17 DEBUG [] - binding null to parameter: 32
20041002 02:12:17 DEBUG [] - binding null to parameter: 33
20041002 02:12:17 DEBUG [] - binding null to parameter: 34
20041002 02:12:17 DEBUG [] - binding 'Architect' to parameter: 35
20041002 02:12:17 DEBUG [] - binding null to parameter: 36
20041002 02:12:17 DEBUG [] - binding null to parameter: 37
20041002 02:12:17 DEBUG [] - binding null to parameter: 38
20041002 02:12:17 DEBUG [] - binding 'true' to parameter: 39
20041002 02:12:17 DEBUG [] - binding null to parameter: 40
20041002 02:12:17 DEBUG [] - binding null to parameter: 41
20041002 02:12:17 DEBUG [] - binding null to parameter: 42
20041002 02:12:17 DEBUG [] - binding 'true' to parameter: 43
20041002 02:12:17 DEBUG [] - binding 'NC DL' to parameter: 44
20041002 02:12:17 DEBUG [] - binding 'true' to parameter: 45
20041002 02:12:17 DEBUG [] - binding null to parameter: 46
20041002 02:12:17 DEBUG [] - binding null to parameter: 47
20041002 02:12:17 DEBUG [] - binding null to parameter: 48
20041002 02:12:17 DEBUG [] - binding 'NC' to parameter: 49
20041002 02:12:17 DEBUG [] - binding '4' to parameter: 50
org.postgresql.util.PSQLException: ERROR: null value in column "submitter_name" violates not-null constraint
at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)
at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:152)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:100)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:517)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:273)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:335)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:461)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:433)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
|