• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Does book suggest best practices?

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike and Merrick

My question to you is does your new book suggest good practices for better maintenance and performance while using JPA2?
I have seen a lot of JPA code that uses JPA queries while the same might be coded using objects only without those where clauses. So does the book draw a line to suggest when to go for queries and when to attempt to achieve results with objects only, and what is the pros and cons of using queries in JPA?

regards
Varun
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the author talks a little bit about this in the "Advanced Topics" section. I would also be interested his opinion
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I wouldn't be very happy with a book that was supposed to be written an an expert in the field but didn't offer some best practices and performance tips ;)

Queries are almost always the way to go. They return exactly the objects that you want, when you want them, without having to navigate through and load other unnecessary objects along the way. If the objects already happen to be in the persistence context then you might be better off just navigating to the objects without doing any db selects, but named queries will typically be your best bet as long as you have your flush mode set to COMMIT and you are not intending to pick up changed objects in your transaction.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mike for your reply. I guess it makes sense.
At the same time I am also concerned about overuse of queries over object navigation. Like user.getAddress().getCity() is coded by some programmers as a query to address and user tables with "where userid=?". This gives me feeling of "going back to jdbc style" instead of object oriented code. So for performance reason it may make sense but not in general. What do you think?

 
Mike Keith
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A simple navigation along single-valued relationships is likely going to be faster in memory because the objects are probably already loaded into the cache/persistence context. This is less common, though. You normally hit a collection fairly soon. Navigating down a single level is fine and typical, going down more levels usually becomes better to use a query (unless you actually want to access all of the intermediate objects as well, of course).
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I will write a book and make sure it has all the worst practices in the world, but make people think it is the way to do it.

Sorry, I woke up really well this morning, but with some sarcasm in my coffee.

Mark
 
Mike Keith
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hah! I actually know of more than one book that seems to have (unwittingly) done exactly that...
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:I think I will write a book and make sure it has all the worst practices in the world, but make people think it is the way to do it.

Sorry, I woke up really well this morning, but with some sarcasm in my coffee.

Mark



Mark, I am eager to see your book appear on JavaRanch Book Promotions
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vyas Sanzgiri wrote:

Mark Spritzler wrote:I think I will write a book and make sure it has all the worst practices in the world, but make people think it is the way to do it.

Sorry, I woke up really well this morning, but with some sarcasm in my coffee.

Mark



Mark, I am eager to see your book appear on JavaRanch Book Promotions



I am sure it would be in the Meaningless Drivel forum.

Mark
 
author & internet detective
Posts: 41086
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:
I am sure it would be in the Meaningless Drivel forum.


Which is where this thread is starting to belong.

Note to all: I'm letting this thread stay because it is joking and involves the authors this week. None of the later posts are eligible to win in the promo of course. (The posters are for their other posts; just mentioning so people don't think chatter counts.)
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Keith wrote:A simple navigation along single-valued relationships is likely going to be faster in memory because the objects are probably already loaded into the cache/persistence context. This is less common, though. You normally hit a collection fairly soon. Navigating down a single level is fine and typical, going down more levels usually becomes better to use a query (unless you actually want to access all of the intermediate objects as well, of course).



Thanks for your expert comments Mike.
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Mark Spritzler wrote:
I am sure it would be in the Meaningless Drivel forum.


Which is where this thread is starting to belong.

Note to all: I'm letting this thread stay because it is joking and involves the authors this week. None of the later posts are eligible to win in the promo of course. (The posters are for their other posts; just mentioning so people don't think chatter counts.)



And now the fun ended. ;)

btw. I am not eligible to win any book.

Mark
 
Jeanne Boyarsky
author & internet detective
Posts: 41086
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:And now the fun ended. ;)


Fun killer me. Imagine that.
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Mark Spritzler wrote:And now the fun ended. ;)


Fun killer me. Imagine that.



FYI, outside of the forums, in real life. Jeanne is a lot of fun to be around.

Mark
 
Mike Keith
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wha, this forum isn't real life?
Now I'm wondering if I should take off these six-shooters I've been wearing around the house.
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Keith wrote:Wha, this forum isn't real life?
Now I'm wondering if I should take off these six-shooters I've been wearing around the house.



Now you have to post pictures.

Mark
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic