cancel
Showing results for 
Search instead for 
Did you mean: 

EJB Integer field with null value in database being set to 0

Former Member
0 Kudos

I've defined an field in a CMP Entity Bean with type java.lang.Integer.

When the bean loads, if this field is null in the database, I always get a 0 value.

I've tried with oracle driver 9.2.0.8 and 10.2.0.2.

I've never had this error working with other Application Servers.

I'm starting to think that the EJB implementation of SAP WAS is very bad.

This field is a foreign key in my database table. Every time the bean load, if it has to make an update of one field, it updates the values all for the fields!!!, trying to set a 0 to this field, and it causes a constraint violation, because there is no register in the related table with id=0.

Help, please.

Accepted Solutions (0)

Answers (1)

Answers (1)

Vlado
Advisor
Advisor
0 Kudos

Hi,

What version and SP of SAP WAS are you using?

Could you elaborate a little bit more on the scenario? Do you use container-managed relationships (CMR)? What does the foreign key column refer to - another CMP bean table or some other table that is not managed by the EJB container?

Best regards,

Vladimir

Former Member
0 Kudos

I'm using NW04sSR1.

I've done more tests, and the scenario is very simple.

I've only one CMP Entity Bean called TestBean, with 3 fields of type java.lang.Integer: field1 (pk), field2, field3. It's pointing to table Test in oracle database 9.2.0.7 (jdbc client 9.2.0.8), with the same 3 fields of type INTEGER and field3 nullable.

I insert a row in the table {1, 1, null}

I get an instance of the Entity from this row, in a test method in my stateless Session Bean, sets field2 to anything and voila! magically field3 mutates to zero 0.

When the beans load, field3 populates with 0 (debug and getField3). So when it makes the full update, of course, it stores this value.

Any idea? Thanks in advance.

Vlado
Advisor
Advisor
0 Kudos

Hi Aníbal,

This is a known limitation in the EJB container in SAP NetWeaver 04 and 04s (please check SAP Note 927201 ). It will be fixed in the next Support Packages.

Thanks and regards,

Vladimir

Former Member
0 Kudos

As a workaround, I use type BigDecimal instead of Integer. It gets the SQL NULL value correctly.

Vlado
Advisor
Advisor
0 Kudos

Yes, this is also a possible workaround.

Former Member
0 Kudos

Hi,

I'm wondering where to finde the solution in note 927201?

As far as I understand, I can neither user primitive-type nor wrappers of primitive types to get null values from db into db-fields? Both types will be initialised to default-value.

This not a solution If you want to distinguish default- and null-value which have different meanings in the business-context?

So the only solution is to use BigDecimal? You can't use long and you can't use java.lang.Long!

Thomas

Vlado
Advisor
Advisor
0 Kudos

As indicated in the note and in the thread above this is a workaround for missing functionality and will most probably be fixed in the next SP.