Query.getResultList() returns null if the table does not exist

View: New views
9 Messages — Rating Filter:   Alert me  

Query.getResultList() returns null if the table does not exist

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am expecting it to return an empty set as per "Effective Java" best practices. I'd like to file a bug report for this. What do you think?

PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this point.

Gili

Re: Query.getResultList() returns null if the table does not exist

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ooops, "empty set" should read "empty list".

Gili

cowwoc wrote:
I am expecting it to return an empty set as per "Effective Java" best practices. I'd like to file a bug report for this. What do you think?

PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this point.

Gili

Re: Query.getResultList() returns null if the table does not exist

by christopher delahunt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't understand how you are not getting an exception if the table
does not exist.  Can you show how you create and execute the query?
Running on an Oracle DB, I get a SQLException: ORA-00942: table or view
does not exist.

Best Regards,
Chris



cowwoc wrote:

> Ooops, "empty set" should read "empty list".
>
> Gili
>
>
> cowwoc wrote:
>  
>> I am expecting it to return an empty set as per "Effective Java" best
>> practices. I'd like to file a bug report for this. What do you think?
>>
>> PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this
>> point.
>>
>> Gili
>>
>>    
>
>  
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

RE: Query.getResultList() returns null if the table does not exist

by mobrien :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gili,
        If you are referring to Item 27: "Return zero-length arrays, not nulls" of Guy Steele's excellent book, we will reread page 134 - keeping lazy initialization and the spec in mind and advise.
        thank you
        /michael

-----Original Message-----
From: cowwoc [mailto:cowwoc@...]
Sent: Monday, November 24, 2008 13:49
To: eclipselink-users@...
Subject: Re: [eclipselink-users] Query.getResultList() returns null if
the table does not exist



Ooops, "empty set" should read "empty list".

Gili


cowwoc wrote:
>
> I am expecting it to return an empty set as per "Effective Java" best
> practices. I'd like to file a bug report for this. What do you think?
>
> PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this
> point.
>
> Gili
>

--
View this message in context: http://www.nabble.com/Query.getResultList%28%29-returns-null-if-the-table-does-not-exist-tp20667095p20667107.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Query.getResultList() returns null if the table does not exist

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am using MySQL. I did "drop database Foo; create database Foo;" and re-ran my application. It worked fine up until this code returned null:

        @Transactional(rollbackOn = Exception.class)
        public List<Terminal> listTerminals()
        {
                Query query = em.get().createQuery("select terminal from " + Terminal.class.getSimpleName() +
                        " as terminal");
                @SuppressWarnings("unchecked")
                List<Terminal> result = query.getResultList();
                return result;
        }

PS: Throwing SQLException seems a bit contrived. The Javadoc says only IllegalStateException may be thrown and as far as I know SQLException is a checked exception.

Gili

Christopher Delahunt wrote:
I don't understand how you are not getting an exception if the table
does not exist.  Can you show how you create and execute the query?
Running on an Oracle DB, I get a SQLException: ORA-00942: table or view
does not exist.

Best Regards,
Chris



cowwoc wrote:
> Ooops, "empty set" should read "empty list".
>
> Gili
>
>
> cowwoc wrote:
>  
>> I am expecting it to return an empty set as per "Effective Java" best
>> practices. I'd like to file a bug report for this. What do you think?
>>
>> PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this
>> point.
>>
>> Gili
>>
>>    
>
>  
_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

RE: Query.getResultList() returns null if the table does not exist

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

mobrien wrote:
Gili,
        If you are referring to Item 27: "Return zero-length arrays, not nulls" of Guy Steele's excellent book, we will reread page 134 - keeping lazy initialization and the spec in mind and advise.
        thank you
        /michael
I was actually referring to "Effective Java" by Joshua Bloch. I'm not familiar with the Guy Steele reference, were you being sarcastic? :)

Gili

Parent Message unknown RE: Query.getResultList() returns null if the table does not exist

by mobrien :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gili,
   Excuse me, I misread the cover without my glasses - I quoted the author of the forward.  Yes, I mean Joshua Bloch's excellent book.
   /michael

----------Original Message----------

From: cowwoc <cowwoc@...>
Sent: Mon, November 24, 2008 2:24 PM
To: eclipselink-users@...
Subject: RE: [eclipselink-users] Query.getResultList() returns null if the table does not exist




mobrien wrote:
>
> Gili,
> If you are referring to Item 27: "Return zero-length arrays, not nulls"
> of Guy Steele's excellent book, we will reread page 134 - keeping lazy
> initialization and the spec in mind and advise.
> thank you
> /michael
>

I was actually referring to "Effective Java" by Joshua Bloch. I'm not
familiar with the Guy Steele reference, were you being sarcastic? :)

Gili
--
View this message in context: http://www.nabble.com/Query.getResultList%28%29-returns-null-if-the-table-does-not-exist-tp20667095p20667833.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Query.getResultList() returns null if the table does not exist

by christopher delahunt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What version are you using?  Chances are you are hitting a bug fixed in
the transaction for bug 247022 that caused the exception to be silently
ignored - try the latest nightly.

MySQL should be throwing an exception, something like
"MySQLSyntaxErrorException: Table 'yourtable' doesn't exist", which will
be wrapped in a
org.eclipse.persistence.exceptions.DatabaseException Runtime exception
type.  

Regards,
Chris



cowwoc wrote:

> I am using MySQL. I did "drop database Foo; create database Foo;" and re-ran
> my application. It worked fine up until this code returned null:
>
> @Transactional(rollbackOn = Exception.class)
> public List<Terminal> listTerminals()
> {
> Query query = em.get().createQuery("select terminal from " +
> Terminal.class.getSimpleName() +
> " as terminal");
> @SuppressWarnings("unchecked")
> List<Terminal> result = query.getResultList();
> return result;
> }
>
> PS: Throwing SQLException seems a bit contrived. The Javadoc says only
> IllegalStateException may be thrown and as far as I know SQLException is a
> checked exception.
>
> Gili
>
>
> Christopher Delahunt wrote:
>  
>> I don't understand how you are not getting an exception if the table
>> does not exist.  Can you show how you create and execute the query?
>> Running on an Oracle DB, I get a SQLException: ORA-00942: table or view
>> does not exist.
>>
>> Best Regards,
>> Chris
>>
>>
>>
>> cowwoc wrote:
>>    
>>> Ooops, "empty set" should read "empty list".
>>>
>>> Gili
>>>
>>>
>>> cowwoc wrote:
>>>  
>>>      
>>>> I am expecting it to return an empty set as per "Effective Java" best
>>>> practices. I'd like to file a bug report for this. What do you think?
>>>>
>>>> PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this
>>>> point.
>>>>
>>>> Gili
>>>>
>>>>    
>>>>        
>>>  
>>>      
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>>
>>    
>
>  
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Query.getResultList() returns null if the table does not exist

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Confirmed, this is fixed in trunk. Thank you!

Gili

Christopher Delahunt wrote:
What version are you using?  Chances are you are hitting a bug fixed in
the transaction for bug 247022 that caused the exception to be silently
ignored - try the latest nightly.

MySQL should be throwing an exception, something like
"MySQLSyntaxErrorException: Table 'yourtable' doesn't exist", which will
be wrapped in a
org.eclipse.persistence.exceptions.DatabaseException Runtime exception
type.  

Regards,
Chris



cowwoc wrote:
> I am using MySQL. I did "drop database Foo; create database Foo;" and re-ran
> my application. It worked fine up until this code returned null:
>
> @Transactional(rollbackOn = Exception.class)
> public List<Terminal> listTerminals()
> {
> Query query = em.get().createQuery("select terminal from " +
> Terminal.class.getSimpleName() +
> " as terminal");
> @SuppressWarnings("unchecked")
> List<Terminal> result = query.getResultList();
> return result;
> }
>
> PS: Throwing SQLException seems a bit contrived. The Javadoc says only
> IllegalStateException may be thrown and as far as I know SQLException is a
> checked exception.
>
> Gili
>
>
> Christopher Delahunt wrote:
>  
>> I don't understand how you are not getting an exception if the table
>> does not exist.  Can you show how you create and execute the query?
>> Running on an Oracle DB, I get a SQLException: ORA-00942: table or view
>> does not exist.
>>
>> Best Regards,
>> Chris
>>
>>
>>
>> cowwoc wrote:
>>    
>>> Ooops, "empty set" should read "empty list".
>>>
>>> Gili
>>>
>>>
>>> cowwoc wrote:
>>>  
>>>      
>>>> I am expecting it to return an empty set as per "Effective Java" best
>>>> practices. I'd like to file a bug report for this. What do you think?
>>>>
>>>> PS: Anyone working on JPA 2.0 should please clarify the Javadoc on this
>>>> point.
>>>>
>>>> Gili
>>>>
>>>>    
>>>>        
>>>  
>>>      
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@eclipse.org
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>>
>>    
>
>  
_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users