persistence@glassfish.java.net

Re: createNamedQuery error

From: christopher delahunt <christopher.delahunt_at_oracle.com>
Date: Thu, 26 Feb 2009 11:08:24 -0500

Hi Richard,

Yes it is correct and I do not see anything wrong with your
annotations. Only thing I can suggest is to use another JPA provider
and see if you get a similar problem. If you don't then it is a
Hibernate specific property or setting that is interfering, and if you
do, then it is something unseen. Someone else on the list might have
encountered something similar with Hibernate, but I would suggest you
try a Hibernate specific forum.

If you try EclipseLink or TopLink Essentials you can turn on logging to
finest - this would show where/when it is processing the annotation and
it might show why it would be choosing the default over the value
specified in the column annotation. If you are using Glassfish,
depending on the version, one or the other is the default JPA provider
anyway (TopLink Essentials in earlier versions, EclipseLink in the
latest version).

Best Regards,
Chris

dhalsim wrote:
> Hi Chris,
>
> The column name in the database is called parent_loc_cd.
>
> I am using the @Column annotation to denote that the column name and the
> entity field are different.
>
> @Id
> @Column(name = "parent_loc_cd")
> private long parentLocationId;
>
> Isn't this a correct way to use @column?
>
> Thanks,
>
> -Richard
>
>
>
>
> Christopher Delahunt wrote:
>
>> I don't know or use Hibernate, so you should probably try their forums
>> to get hibernate specific help, but nothing seems to be wrong with the
>> annotations themselves. Do you have a PARENTLOCATIONID column in the
>> database?
>>
>> Regards,
>> Chris
>>
>> dhalsim wrote:
>>
>>> Hi,
>>> I created the following NamedQuery in my entity class:
>>>
>>> @NamedQuery
>>> (name = LocationGroupEntity.QUERY_FIND_CHILD_LOCATION_BY_PARENT_LOCATION,
>>> query = "select l from LocationGroupEntity l where l.parentLocationId =
>>> :parentLocationId and l.isActive = true"
>>> )
>>>
>>> Here's how I defined the field in the class:
>>>
>>> @Id
>>> @Column(name = "parent_loc_cd")
>>> private long parentLocationId;
>>>
>>> When I executed the code that will execute the query and get the result,
>>> I
>>> encountered the following error:
>>>
>>> Hibernate: select locationgr0_.childLocationId as childLoc1_9_,
>>> locationgr0_.parentLocationId as parentLo2_9_, locationgr0_.active_ind as
>>> active3_9_ from LOCATION_GROUP locationgr0_ where
>>> locationgr0_.parentLocationId=? and locationgr0_.active_ind=1
>>> 0 [btpool3-1] WARN org.hibernate.util.JDBCExceptionReporter - SQL
>>> Error: 904, SQLState: 42000
>>> 15 [btpool3-1] ERROR org.hibernate.util.JDBCExceptionReporter -
>>> ORA-00904: "LOCATIONGR0_"."PARENTLOCATIONID": invalid identifier
>>>
>>> Here's the snippet of the code that was executed:
>>>
>>> final Query query =
>>> entityManager.createNamedQuery(LocationGroupEntity.QUERY_FIND_CHILD_LOCATION_BY_PARENT_LOCATION);
>>>
>>> query.setParameter("parentLocationId",
>>> SimpleMID.getCanonicalValue(criteria.getLocationMID()));
>>>
>>> final List<LocationGroupEntity> LocationGroupEntities =
>>> query.getResultList(); // This is where the exception was thrown.
>>>
>>> I think the syntax of the query is correct, so I am not sure why it
>>> doesn't
>>> recognize the parentLocationId. I attached the full class in case
>>> somebody
>>> want to take a look at it.
>>> Any suggestions on what I might miss will be appreciated.
>>>
>>> Thanks,
>>>
>>> Dhalsim http://www.nabble.com/file/p22217390/LocationGroupEntity.java
>>> LocationGroupEntity.java
>>> http://www.nabble.com/file/p22217390/LocationGroupKey.java
>>> LocationGroupKey.java
>>>
>>>
>>
>
>