You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by gav <ga...@hotmail.com> on 2007/11/28 10:29:21 UTC

OpenJPA MySQL Environment: NamedQuery always returns null for @Enumerated column types

Hello, i have a WebsphereCE application environment (OpenEJB/OpenJPA
1.0.0/MySQL 5.0.27 with JDBC driver 3.1.14).
When running a NamedQuery on the Entity Bean i find the returned object is
fully populated as expected EXCEPT for the Enum(erated) type which always
came back null (in error).

@Entity
@Table( name = "Client" )
@NamedQueries( {
...
        @NamedQuery( name = "Client.getClientCasenoteDataByEmpiId", query =
"select c from Client c JOIN FETCH c.assets where c.epmiId = :epmiId" ),
...
public class Client implements Serializable {
...
    @Column( name = "Gender" )
    @Enumerated( EnumType.STRING )
    private Gender            gender           = Gender.UNSPECIFIED;

// This gender field in the Client object graph always comes back null
despite the database having a column definition consistent with storing the
enum values as strings in database.

Gender varchar(255) NULL     (a column definition confirmed by
autogeneration by openjpa using synchronizemappings property)...

Enum class is

public enum Gender {

    MALE, FEMALE, UNSPECIFIED;


For the record also tried the default ordinal approach, also the MySQL
3.1.12,3.1.14 and 5.0.4 JDBC Drivers but always get nothing back but null.
Has anyone seen this problem or could point me in the right direction ???
thanks for your help !

 
-- 
View this message in context: http://www.nabble.com/OpenJPA-MySQL-Environment%3A-NamedQuery-always-returns-null-for-%40Enumerated-column-types-tf4887323.html#a13988839
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Hooray - this works ! - Re: OpenJPA MySQL Environment: NamedQuery always returns null for @Enumerated column types

Posted by pl...@gmail.com.
Great. FTR I agree that it should be eager by default. I thought we
fixed this recently.

-Patrick

On 11/28/07, gav <ga...@hotmail.com> wrote:
>
> Dah ! thankyou ...the following works
> (for the record i assumed Eager loading was  default for Enum since
> one-to-one mapping?!)
>
>     @Column( name = "Gender" )
>     @Basic( fetch = FetchType.EAGER )
>     @Enumerated( EnumType.STRING )
>     private Gender            gender           = Gender.UNSPECIFIED;
>
> -----------------------
>
>
>
>
>
> Patrick Linskey-2 wrote:
> >
> > Hi,
> >
> > Are you using the OpenJPA enhancer? What happens if you explicitly set
> > the fetch mode to eager in the @Enumerated annotation?
> >
> > -Patrick
> >
> > On 11/28/07, gav <ga...@hotmail.com> wrote:
> >>
> >> Hello, i have a WebsphereCE application environment (OpenEJB/OpenJPA
> >> 1.0.0/MySQL 5.0.27 with JDBC driver 3.1.14).
> >> When running a NamedQuery on the Entity Bean i find the returned object
> >> is
> >> fully populated as expected EXCEPT for the Enum(erated) type which always
> >> came back null (in error).
> >>
> >> @Entity
> >> @Table( name = "Client" )
> >> @NamedQueries( {
> >> ...
> >>         @NamedQuery( name = "Client.getClientCasenoteDataByEmpiId", query
> >> =
> >> "select c from Client c JOIN FETCH c.assets where c.epmiId = :epmiId" ),
> >> ...
> >> public class Client implements Serializable {
> >> ...
> >>     @Column( name = "Gender" )
> >>     @Enumerated( EnumType.STRING )
> >>     private Gender            gender           = Gender.UNSPECIFIED;
> >>
> >> // This gender field in the Client object graph always comes back null
> >> despite the database having a column definition consistent with storing
> >> the
> >> enum values as strings in database.
> >>
> >> Gender varchar(255) NULL     (a column definition confirmed by
> >> autogeneration by openjpa using synchronizemappings property)...
> >>
> >> Enum class is
> >>
> >> public enum Gender {
> >>
> >>     MALE, FEMALE, UNSPECIFIED;
> >>
> >>
> >> For the record also tried the default ordinal approach, also the MySQL
> >> 3.1.12,3.1.14 and 5.0.4 JDBC Drivers but always get nothing back but
> >> null.
> >> Has anyone seen this problem or could point me in the right direction ???
> >> thanks for your help !
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/OpenJPA-MySQL-Environment%3A-NamedQuery-always-returns-null-for-%40Enumerated-column-types-tf4887323.html#a13988839
> >> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Patrick Linskey
> > 202 669 5907
> >
> >
> :-D:-D
> --
> View this message in context:
> http://www.nabble.com/OpenJPA-MySQL-Environment%3A-NamedQuery-always-returns-null-for-%40Enumerated-column-types-tf4887323.html#a13995534
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>


-- 
Patrick Linskey
202 669 5907

Hooray - this works ! - Re: OpenJPA MySQL Environment: NamedQuery always returns null for @Enumerated column types

Posted by gav <ga...@hotmail.com>.
Dah ! thankyou ...the following works 
(for the record i assumed Eager loading was  default for Enum since
one-to-one mapping?!)

    @Column( name = "Gender" )
    @Basic( fetch = FetchType.EAGER )
    @Enumerated( EnumType.STRING )
    private Gender            gender           = Gender.UNSPECIFIED;

-----------------------





Patrick Linskey-2 wrote:
> 
> Hi,
> 
> Are you using the OpenJPA enhancer? What happens if you explicitly set
> the fetch mode to eager in the @Enumerated annotation?
> 
> -Patrick
> 
> On 11/28/07, gav <ga...@hotmail.com> wrote:
>>
>> Hello, i have a WebsphereCE application environment (OpenEJB/OpenJPA
>> 1.0.0/MySQL 5.0.27 with JDBC driver 3.1.14).
>> When running a NamedQuery on the Entity Bean i find the returned object
>> is
>> fully populated as expected EXCEPT for the Enum(erated) type which always
>> came back null (in error).
>>
>> @Entity
>> @Table( name = "Client" )
>> @NamedQueries( {
>> ...
>>         @NamedQuery( name = "Client.getClientCasenoteDataByEmpiId", query
>> =
>> "select c from Client c JOIN FETCH c.assets where c.epmiId = :epmiId" ),
>> ...
>> public class Client implements Serializable {
>> ...
>>     @Column( name = "Gender" )
>>     @Enumerated( EnumType.STRING )
>>     private Gender            gender           = Gender.UNSPECIFIED;
>>
>> // This gender field in the Client object graph always comes back null
>> despite the database having a column definition consistent with storing
>> the
>> enum values as strings in database.
>>
>> Gender varchar(255) NULL     (a column definition confirmed by
>> autogeneration by openjpa using synchronizemappings property)...
>>
>> Enum class is
>>
>> public enum Gender {
>>
>>     MALE, FEMALE, UNSPECIFIED;
>>
>>
>> For the record also tried the default ordinal approach, also the MySQL
>> 3.1.12,3.1.14 and 5.0.4 JDBC Drivers but always get nothing back but
>> null.
>> Has anyone seen this problem or could point me in the right direction ???
>> thanks for your help !
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/OpenJPA-MySQL-Environment%3A-NamedQuery-always-returns-null-for-%40Enumerated-column-types-tf4887323.html#a13988839
>> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 
:-D:-D
-- 
View this message in context: http://www.nabble.com/OpenJPA-MySQL-Environment%3A-NamedQuery-always-returns-null-for-%40Enumerated-column-types-tf4887323.html#a13995534
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: OpenJPA MySQL Environment: NamedQuery always returns null for @Enumerated column types

Posted by pl...@gmail.com.
Hi,

Are you using the OpenJPA enhancer? What happens if you explicitly set
the fetch mode to eager in the @Enumerated annotation?

-Patrick

On 11/28/07, gav <ga...@hotmail.com> wrote:
>
> Hello, i have a WebsphereCE application environment (OpenEJB/OpenJPA
> 1.0.0/MySQL 5.0.27 with JDBC driver 3.1.14).
> When running a NamedQuery on the Entity Bean i find the returned object is
> fully populated as expected EXCEPT for the Enum(erated) type which always
> came back null (in error).
>
> @Entity
> @Table( name = "Client" )
> @NamedQueries( {
> ...
>         @NamedQuery( name = "Client.getClientCasenoteDataByEmpiId", query =
> "select c from Client c JOIN FETCH c.assets where c.epmiId = :epmiId" ),
> ...
> public class Client implements Serializable {
> ...
>     @Column( name = "Gender" )
>     @Enumerated( EnumType.STRING )
>     private Gender            gender           = Gender.UNSPECIFIED;
>
> // This gender field in the Client object graph always comes back null
> despite the database having a column definition consistent with storing the
> enum values as strings in database.
>
> Gender varchar(255) NULL     (a column definition confirmed by
> autogeneration by openjpa using synchronizemappings property)...
>
> Enum class is
>
> public enum Gender {
>
>     MALE, FEMALE, UNSPECIFIED;
>
>
> For the record also tried the default ordinal approach, also the MySQL
> 3.1.12,3.1.14 and 5.0.4 JDBC Drivers but always get nothing back but null.
> Has anyone seen this problem or could point me in the right direction ???
> thanks for your help !
>
>
> --
> View this message in context:
> http://www.nabble.com/OpenJPA-MySQL-Environment%3A-NamedQuery-always-returns-null-for-%40Enumerated-column-types-tf4887323.html#a13988839
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>


-- 
Patrick Linskey
202 669 5907

Re: OpenJPA MySQL Environment: NamedQuery always returns null for @Enumerated column types

Posted by lavanyapmr <la...@gmail.com>.
RESOLVED.

It's my bad. 
Query had enum values instead of variable names.
Exception stack trace just says NumberFormatExcpetion and doesn't say
anything about the variables/values.
I switched to Annotation and exception stack trace showed me the real error.

Eager Fetching worked both in XML and java annotations.
now I'm back to XML.

Thanks!
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-Environment-NamedQuery-always-returns-null-for-Enumerated-column-types-tp216529p5970970.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: OpenJPA MySQL Environment: NamedQuery always returns null for @Enumerated column types

Posted by lavanyapmr <la...@gmail.com>.
I'm facing similar issue now.
Environment : Sybase database , Open JPA 1.1.0

I'm using Native names queries.
and Entity mapping is also done in orm.xml file, but not Annotations.

I've tried following:
<named-native-query name="testEnum1"
result-class="com.proj.test.ojpa.TaskCode">
	<query>
	<![CDATA[ 
	SELECT m.nbr_mrtg_fm as loanId, m.dt_fund as myDate,
	case when mc.code_chartc in ('RECAST') 
	     then 'Recast'       
	     else null  
	end as codePurpose
	from mrtg m 
	left outer join mrtg_chartc  mc         
	    on  m.id_mrtg = mc.id_mrtg 
	    and mc.dt_eff_end  is null 
	    and mc.code_chartc in ('LTF','RECAST') 
	WHERE m.dt_fund between '01/01/2010' and '01/08/2010'
	]]>
	</query>
</named-native-query>
	
	
<entity class="com.proj.test.ojpa.TaskCode">
	<table name="mrtg" />
	<attributes>
		<id name="loanId"></id>
		<basic name="myDate">
			<temporal>DATE</temporal>
		</basic>
		<basic name="codePurpose" fetch="EAGER" optional="true">				
			<enumerated>STRING</enumerated>
		</basic>
	</attributes>
</entity>

Where am I doing wrong??
Thanks



-- 
View this message in context: http://openjpa.208410.n2.nabble.com/OpenJPA-MySQL-Environment-NamedQuery-always-returns-null-for-Enumerated-column-types-tp216529p5967959.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.