Reputation: 210
I've run into an interesting play on the infamous inserting null fields from the Entity into a database.
Say I have the following table
ID | Number(10) | Not Null
Some_Number | Number(25) | Nullable
Some_Date | DATE Default(sysDate) | Nullable
I have the following Entity
@Entity
@Table(name="SOME_TABLE")
public class MockEntity implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name="ID", nullable=false)
private Long myId;
@Column(name="SOME_NUMBER")
private Long someNumber;
@Column(name="SOME_DATE")
private Date someDate;
//Basic getters and setters here
}
The Perssitence Uint in my persistence.xml is as follows
<persistence-unit name="someSortOfPU" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="show_sql" value="true"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="javax.persistence.jdbc.url" value="someUrl"/>
<property name="javax.persistence.jdbc.user" value="someUser"/>
<property name="javax.persistence.jdbc.password" value="somePassword"/>
</properties>
</persistence-unit>
The test case is persisting a MockEntity object with an ID and a Date, no SomeNumber is set
MockEntity testEntity = new MockEntity();
testEntity.setMyId(999999l);
testEntity.setSomeDate(new Date());
When I use the ojdbc14.jar with an Oracle 10g database, my junit gets the following error
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("SOME_TABLE"."SOME_NUMBER")
When I use ojdbc14.jar with an Oracle 11g database, my junit completes successfully. The row exists in the table.
I've attempted to use the ojbc5.jars in hopes of having this issue disappear, but no luck.
Does Oracle 10g interpret the Hibernate generated sql:
insert into SOME_TABLE (ID, SOME_NUMBER, SOME_DATE) values (?, ?, ?)
where the there is a null in the parameter passed to the statement differently than 11g, and how can I get the expected results on 10g?
Upvotes: 2
Views: 5090
Reputation: 210
@axtavt was correct...the schema's were different. Egg on my face for not beginning my troubleshooting at the source!
Upvotes: 1