Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Bug when using Converter that converts to NULL?

Hello,

I'm accessing a View in the Oracle Database.

Driver: Oracle Database 11g Release 2 (11.2.0.4) JDBC Drivers
EclipseLink: Version 2.5.1

The Table is actually a View in the Oracle DB and
the column CLOSED_STATUS is defined as VARCHAR2 (1 byte) and can have either
of two values:
NULL or "+".

The Entity I defined has the following Column:

@Column(name="CLOSED_STATUS", unique = false, nullable = true)
@Convert(converter = BooleanPlusNullConverter.class)
private Boolean closedStatus;


The Converter will convert true to "+" and false or NULL to null:

@Converter
@SuppressWarnings("nls")
public final class BooleanPlusNullConverter implements
AttributeConverter<Boolean, String> {

	/** The {@code +} sign (value: <code>{@value}</code>). */
	private static final String PLUS_SIGN = "+";

	/** {@inheritDoc} */
	@Override
	public String convertToDatabaseColumn(final Boolean value) {
		if (value != null && value) {
			return PLUS_SIGN;
		}
		return null;
	}

	/** {@inheritDoc} */
	@Override
	public Boolean convertToEntityAttribute(final String value) {
		if (value == null || !PLUS_SIGN.equals(value)) {
			return Boolean.FALSE;
		}
		return Boolean.TRUE;
	}
}

Here is the named query I use:

	<named-query name="getByClosedStatus">
		<query>
			select obj.id
			from issue obj
			where obj.closedStatus = :closedStatus
		</query>
	</named-query>


final Query query = entityManager.createNamedQuery(name);
Then set the parameter :closedStatus to false and call the query.
query.getResultList()

Resulting error:

Internal Exception: java.sql.SQLSyntaxErrorException: ORA-01722: invalid
number
Error Code: 1722
Call: SELECT ID FROM DB_ADM.ISSUE WHERE (CLOSED_STATUS = ?)
	bind => [null]

Notes:
The error doesnt happen if I set the parameter to true.



--
View this message in context: http://eclipse.1072660.n5.nabble.com/Bug-when-using-Converter-that-converts-to-NULL-tp167223.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.


Back to the top