Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] LIKE expression with enum

To work around the problem of the column names in the result set not
matching the column names defined in the class you can use the AS
keyword.

SELECT columnInResultSet AS columnDefinedInClass FROM .....

I know, I know, this is more tedious than just doing SELECT *

Zarar

On Fri, May 1, 2009 at 2:42 PM, cmathrusse
<Christopher.Mathrusse@xxxxxxxxxx> wrote:
> A simple problem has caused me a great deal of time. I've got an entity as
> follows:
>
> public class ResourceDefinition implements Serializable {
> @Column( name = "content", nullable = false )
> private String content;
>
> @Column( name = "create_date", nullable = false )
> @Temporal( javax.persistence.TemporalType.TIMESTAMP )
> private java.util.Calendar createDate;
>
> @Id
> @Enumerated(EnumType.STRING)
> @Column( name = "id", length = 10)
> private ResourceKey id;
>
> @Column( name = "mod_date", nullable = false )
> @Temporal( javax.persistence.TemporalType.TIMESTAMP )
> private java.util.Calendar modDate;
>
> @ManyToOne
> @JoinColumn(name = "severity", nullable = false)
> private Severity severity;
>
> @Column( name = "version", nullable = false )
> @Version
> private int version;
>
>
> The Primary Key, ResourceKey, is a simple enum:
> public enum ResourceKey { ADR_001, .... }
>
> The issue that I am having is that we would like to perform a SELECT
> object(o) FROM ResourceDefinition WHERE id LIKE :param
> The problem is that we cannot supply a string for the param as the the param
> would be a String and the id is an enum.
>
> So it seemed to me that the easiest way around this issue was to write a
> NativeQuery. SELECT * FROM resource_definition WHERE id LIKE ?1
>
> But this produced the following exception: Local Exception Stack:
>
> Exception [EclipseLink-6044] (Eclipse Persistence Services - 1.1.0.r3634):
> org.eclipse.persistence.exceptions.QueryException Exception Description: The
> primary key read from the row [DatabaseRecord(
>
> => ORD_001
>
> => Order Number: [{0}], Process: [{1}] has been updated to 'PENDING'
>
> => 2008-12-01 00:00:00.0
>
> => 2008-12-01 00:00:00.0
>
> => 1
>
> => INFO)] during the execution of the query was detected to be null. Primary
> keys must not contain null.
>
> Query: ReadAllQuery(name="ResourceDefinition.findMatchingResources"
> referenceClass=ResourceDefinition sql="SELECT * FROM resource_definition
> WHERE id LIKE ?")
>
> Searching the internet I found that this is caused by a mismatch between the
> column names returned in the resultSet vs. those defined on the class.
> Currently we are developing using a JavaDB on our local machines, but when
> we go into Test and Production it will be Sybase ASE. I didn't think this
> would be an issue but as I have discovered, with JavaDB, EclipseLink
> generates the DDL with unquoted table and column names. This results in
> tables and columns being defined in uppercase. With Sybase ASE, unquoted
> table and column names are defined in lowercase.
>
> So, a simply LIKE expression has caused me a good amount of grief. Do you
> have any suggestions as to how I can get around these issues?
>
> Thanks for the help.
> ________________________________
> View this message in context: LIKE expression with enum
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>


Back to the top